답안 #513152

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
513152 2022-01-17T02:43:19 Z 79brue Worst Reporter 2 (JOI16_worst_reporter2) C++14
60 / 100
2000 ms 13664 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct dat{
    int x, y; bool d; /// 0: 진입
    dat(){}
    dat(int x, int y, bool d): x(x), y(y), d(d){}
    bool operator<(const dat &r)const{
        if(y != r.y) return y < r.y;
        return d < r.d;
    }
};

int n;
vector<dat> vec;
int cnt[200002];
int ans;

int main(){
    scanf("%d", &n);
    for(int i=1; i<=n; i++){
        int x, y;
        scanf("%d %d", &x, &y);
        vec.push_back(dat(x, y, 0));
    }
    for(int i=1; i<=n; i++){
        int x, y;
        scanf("%d %d", &x, &y);
        vec.push_back(dat(x, y, 1));
    }
    sort(vec.begin(), vec.end());

    for(int i=0; i<n+n; i++){
        if(vec[i].d == 0){
            cnt[vec[i].x]++;
            continue;
        }
        if(cnt[vec[i].x]){
            cnt[vec[i].x]--;
            continue;
        }
        ans++;

        vector<int> problem (n+5, 1e9);
        vector<int> sum (n+5, 0);
        for(int j=1; j<=n; j++) sum[j] = cnt[j] - 1;
        for(int j=i; j<n+n; j++){
            if(vec[j].d == 0) sum[vec[j].x]++;
            else if(sum[vec[j].x]) sum[vec[j].x]--;
            else problem[vec[j].x] = min(problem[vec[j].x], j);
        }
        int key = 0, val = -1;
        for(int j=1; j<=n; j++) if(cnt[j] && problem[j] > val) val = problem[j], key = j;

        cnt[key]--;
    }
    printf("%d", ans);
}

Compilation message

worst_reporter2.cpp: In function 'int main()':
worst_reporter2.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
worst_reporter2.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         scanf("%d %d", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~
worst_reporter2.cpp:31:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |         scanf("%d %d", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 308 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 308 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 0 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 308 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 308 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 0 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 0 ms 208 KB Output is correct
15 Correct 0 ms 208 KB Output is correct
16 Correct 0 ms 208 KB Output is correct
17 Correct 0 ms 208 KB Output is correct
18 Correct 1 ms 312 KB Output is correct
19 Correct 0 ms 208 KB Output is correct
20 Correct 0 ms 208 KB Output is correct
21 Correct 0 ms 208 KB Output is correct
22 Correct 0 ms 308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 308 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 308 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 0 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 0 ms 208 KB Output is correct
15 Correct 0 ms 208 KB Output is correct
16 Correct 0 ms 208 KB Output is correct
17 Correct 0 ms 208 KB Output is correct
18 Correct 1 ms 312 KB Output is correct
19 Correct 0 ms 208 KB Output is correct
20 Correct 0 ms 208 KB Output is correct
21 Correct 0 ms 208 KB Output is correct
22 Correct 0 ms 308 KB Output is correct
23 Correct 145 ms 720 KB Output is correct
24 Correct 143 ms 704 KB Output is correct
25 Correct 148 ms 700 KB Output is correct
26 Correct 158 ms 708 KB Output is correct
27 Correct 98 ms 720 KB Output is correct
28 Correct 26 ms 692 KB Output is correct
29 Correct 67 ms 592 KB Output is correct
30 Correct 80 ms 656 KB Output is correct
31 Correct 158 ms 648 KB Output is correct
32 Correct 6 ms 692 KB Output is correct
33 Correct 17 ms 592 KB Output is correct
34 Correct 37 ms 648 KB Output is correct
35 Correct 37 ms 644 KB Output is correct
36 Correct 125 ms 592 KB Output is correct
37 Correct 7 ms 684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 308 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 308 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 0 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 0 ms 208 KB Output is correct
15 Correct 0 ms 208 KB Output is correct
16 Correct 0 ms 208 KB Output is correct
17 Correct 0 ms 208 KB Output is correct
18 Correct 1 ms 312 KB Output is correct
19 Correct 0 ms 208 KB Output is correct
20 Correct 0 ms 208 KB Output is correct
21 Correct 0 ms 208 KB Output is correct
22 Correct 0 ms 308 KB Output is correct
23 Correct 145 ms 720 KB Output is correct
24 Correct 143 ms 704 KB Output is correct
25 Correct 148 ms 700 KB Output is correct
26 Correct 158 ms 708 KB Output is correct
27 Correct 98 ms 720 KB Output is correct
28 Correct 26 ms 692 KB Output is correct
29 Correct 67 ms 592 KB Output is correct
30 Correct 80 ms 656 KB Output is correct
31 Correct 158 ms 648 KB Output is correct
32 Correct 6 ms 692 KB Output is correct
33 Correct 17 ms 592 KB Output is correct
34 Correct 37 ms 648 KB Output is correct
35 Correct 37 ms 644 KB Output is correct
36 Correct 125 ms 592 KB Output is correct
37 Correct 7 ms 684 KB Output is correct
38 Execution timed out 2087 ms 13664 KB Time limit exceeded
39 Halted 0 ms 0 KB -