Submission #2885252


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int amax[100005];
int bmin[100005];


int main(){
    int n,m;
    int a,b;
    int ans=1;

    cin >> n >> m;
    vector<pair<int,int>> ab(m);

    for(int i=0; i<m; i++){
        cin>>a>>b;
        if(a>b){swap(a,b);}
        ab[i].first=a;
        ab[i].second=b;
    }

    sort(ab.begin(),ab.end());
    amax[0]=ab[0].first;
    bmin[0]=ab[0].second;

    for(int i=1; i<m; i++){
        for(int j=0; j<ans; j++){
            if(bmin[j]>ab[i].first && amax[j]<ab[i].second){
                amax[j] = max(amax[j], ab[i].first);
                bmin[j] = min(bmin[j], ab[i].second);
                break;
            }else if(j==ans-1){
                amax[ans] = ab[i].first;
                bmin[ans] = ab[i].second;
                ans++;
                break;
            }
        }
    }

    cout<<ans<<endl;
    return 0;
}

Submission Info

Submission Time
Task D - Islands War
User u_sho
Language C++14 (GCC 5.4.1)
Score 400
Code Size 953 Byte
Status AC
Exec Time 82 ms
Memory 1024 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 44
Set Name Test Cases
Sample sample_01, sample_02, sample_03
All 0_small_0, 0_small_1, 0_small_10, 0_small_2, 0_small_3, 0_small_4, 0_small_5, 0_small_6, 0_small_7, 0_small_8, 0_small_9, 1_rand_0, 1_rand_1, 1_rand_2, 1_rand_3, 1_rand_4, 1_rand_5, 1_rand_6, 1_rand_7, 1_rand_8, 1_rand_9, 2_max_0, 2_max_1, 2_max_2, 2_max_3, 2_max_4, 2_max_5, 2_max_6, 2_max_7, 2_max_8, 2_max_9, 3_nosub_0, 3_nosub_1, 3_nosub_2, 3_nosub_3, 3_nosub_4, 3_nosub_5, 3_nosub_6, 3_nosub_7, 3_nosub_8, 3_nosub_9, sample_01, sample_02, sample_03
Case Name Status Exec Time Memory
0_small_0 AC 1 ms 256 KB
0_small_1 AC 1 ms 256 KB
0_small_10 AC 1 ms 256 KB
0_small_2 AC 1 ms 256 KB
0_small_3 AC 1 ms 256 KB
0_small_4 AC 1 ms 256 KB
0_small_5 AC 1 ms 256 KB
0_small_6 AC 1 ms 256 KB
0_small_7 AC 1 ms 256 KB
0_small_8 AC 1 ms 256 KB
0_small_9 AC 1 ms 256 KB
1_rand_0 AC 4 ms 256 KB
1_rand_1 AC 30 ms 512 KB
1_rand_2 AC 67 ms 896 KB
1_rand_3 AC 68 ms 1024 KB
1_rand_4 AC 10 ms 384 KB
1_rand_5 AC 57 ms 896 KB
1_rand_6 AC 30 ms 640 KB
1_rand_7 AC 52 ms 896 KB
1_rand_8 AC 21 ms 512 KB
1_rand_9 AC 63 ms 896 KB
2_max_0 AC 76 ms 1024 KB
2_max_1 AC 82 ms 1024 KB
2_max_2 AC 78 ms 1024 KB
2_max_3 AC 76 ms 1024 KB
2_max_4 AC 76 ms 1024 KB
2_max_5 AC 76 ms 1024 KB
2_max_6 AC 75 ms 1024 KB
2_max_7 AC 76 ms 1024 KB
2_max_8 AC 76 ms 1024 KB
2_max_9 AC 76 ms 1024 KB
3_nosub_0 AC 67 ms 1024 KB
3_nosub_1 AC 67 ms 1024 KB
3_nosub_2 AC 67 ms 1024 KB
3_nosub_3 AC 67 ms 1024 KB
3_nosub_4 AC 67 ms 1024 KB
3_nosub_5 AC 67 ms 1024 KB
3_nosub_6 AC 67 ms 1024 KB
3_nosub_7 AC 67 ms 1024 KB
3_nosub_8 AC 67 ms 1024 KB
3_nosub_9 AC 67 ms 1024 KB
sample_01 AC 1 ms 256 KB
sample_02 AC 1 ms 256 KB
sample_03 AC 1 ms 256 KB