답안 #411628

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
411628 2021-05-25T16:08:15 Z RGBB Bread First Search (CCO21_day2problem2) C++14
25 / 25
63 ms 13536 KB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int>pp;
const int MAX=200000;
int n,m,outp,adj[MAX],leftmost[MAX],diff[MAX];
vector<int>best[MAX];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>m;
    for(int i=0;i<n;i++)adj[i]=(1<<30);
    for(int i=0;i<n;i++)leftmost[i]=(1<<30);
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        adj[max(a,b)]=min(adj[max(a,b)],min(a,b));
    }
    leftmost[n-1]=min(adj[n-1],n-2);
    for(int i=n-2;i>=0;i--)leftmost[i]=min(leftmost[i+1],min(adj[i],i-1));
    for(int i=0;i<n;i++){
        if(adj[i]==(1<<30))continue;
        diff[adj[i]+1]++;
        if(i+1<n)diff[i+1]--;
    }
    for(int i=1;i<n;i++)diff[i]+=diff[i-1];
    int cur=0;
    for(int i=n-1;i>=1;i--){
        for(int y:best[i])cur=max(cur,y);
        best[leftmost[i]].push_back(cur+diff[i]);
        if(i==1)cout<<n-1-cur-diff[i]<<"\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5024 KB Output is correct
2 Correct 3 ms 5016 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 5 ms 4924 KB Output is correct
5 Correct 5 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 4 ms 4940 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 4 ms 4940 KB Output is correct
10 Correct 4 ms 4940 KB Output is correct
11 Correct 4 ms 4940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5024 KB Output is correct
2 Correct 3 ms 5016 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 5 ms 4924 KB Output is correct
5 Correct 5 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 4 ms 4940 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 4 ms 4940 KB Output is correct
10 Correct 4 ms 4940 KB Output is correct
11 Correct 4 ms 4940 KB Output is correct
12 Correct 4 ms 5024 KB Output is correct
13 Correct 3 ms 5016 KB Output is correct
14 Correct 4 ms 4940 KB Output is correct
15 Correct 5 ms 4924 KB Output is correct
16 Correct 5 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 4 ms 4940 KB Output is correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 4 ms 4940 KB Output is correct
21 Correct 4 ms 4940 KB Output is correct
22 Correct 4 ms 4940 KB Output is correct
23 Correct 6 ms 5196 KB Output is correct
24 Correct 4 ms 5068 KB Output is correct
25 Correct 7 ms 5068 KB Output is correct
26 Correct 7 ms 5068 KB Output is correct
27 Correct 7 ms 5068 KB Output is correct
28 Correct 8 ms 5068 KB Output is correct
29 Correct 4 ms 5020 KB Output is correct
30 Correct 11 ms 5068 KB Output is correct
31 Correct 12 ms 5068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5024 KB Output is correct
2 Correct 3 ms 5016 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 5 ms 4924 KB Output is correct
5 Correct 5 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 4 ms 4940 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 4 ms 4940 KB Output is correct
10 Correct 4 ms 4940 KB Output is correct
11 Correct 4 ms 4940 KB Output is correct
12 Correct 4 ms 5024 KB Output is correct
13 Correct 3 ms 5016 KB Output is correct
14 Correct 4 ms 4940 KB Output is correct
15 Correct 5 ms 4924 KB Output is correct
16 Correct 5 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 4 ms 4940 KB Output is correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 4 ms 4940 KB Output is correct
21 Correct 4 ms 4940 KB Output is correct
22 Correct 4 ms 4940 KB Output is correct
23 Correct 6 ms 5196 KB Output is correct
24 Correct 4 ms 5068 KB Output is correct
25 Correct 7 ms 5068 KB Output is correct
26 Correct 7 ms 5068 KB Output is correct
27 Correct 7 ms 5068 KB Output is correct
28 Correct 8 ms 5068 KB Output is correct
29 Correct 4 ms 5020 KB Output is correct
30 Correct 11 ms 5068 KB Output is correct
31 Correct 12 ms 5068 KB Output is correct
32 Correct 22 ms 13536 KB Output is correct
33 Correct 12 ms 8528 KB Output is correct
34 Correct 53 ms 7472 KB Output is correct
35 Correct 56 ms 8208 KB Output is correct
36 Correct 63 ms 8344 KB Output is correct
37 Correct 63 ms 8376 KB Output is correct
38 Correct 9 ms 8444 KB Output is correct
39 Correct 10 ms 8396 KB Output is correct
40 Correct 26 ms 6856 KB Output is correct
41 Correct 50 ms 7728 KB Output is correct
42 Correct 58 ms 8476 KB Output is correct
43 Correct 53 ms 8356 KB Output is correct
44 Correct 4 ms 4940 KB Output is correct
45 Correct 4 ms 4996 KB Output is correct