답안 #186614

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
186614 2020-01-12T08:51:42 Z Ruxandra985 Alternating Current (BOI18_alternating) C++14
55 / 100
3000 ms 1108 KB
#include <bits/stdc++.h>
#define DIMN 100010
using namespace std;
pair <int,int> v[DIMN];
int d[DIMN] , cer[DIMN] , f[DIMN] , sol[DIMN];
int main()
{
    FILE *fin = stdin;
    FILE *fout = stdout;
    int n , m , i , j , ok , poz , what;
    fscanf (fin,"%d%d",&n,&m);
    for (i=1;i<=m;i++){
        fscanf (fin,"%d%d",&v[i].first,&v[i].second);
        if (v[i].first <= v[i].second){
            for (j = v[i].first ; j <= v[i].second ; j++){
                d[j]++;
            }
        }
        else {
            for (j = v[i].first ; j <= n ; j++){
                d[j]++;
            }
            for (j = 1 ; j <= v[i].second ; j++){
                d[j]++;
            }
        }
    }
    for (j=1;j<=m;j++){
 
        ok = 0;
        for (i=1;i<=n;i++){
            if (d[i] == 1 && cer[i] < 3 && cer[i] > 0)
                ok = i;
        }
 
        if (ok){
 
            for (i=1;i<=m;i++){
                if (!f[i]){ /// inca e relevant
                    if (v[i].first <= v[i].second && v[i].first <= ok && ok <= v[i].second){
                        poz = i;
                        f[i] = 1;
                    }
                    else if (v[i].first > v[i].second && (ok >= v[i].first || ok <= v[i].second)){
                        poz = i;
                        f[i] = 1;
                    }
                }
            }
 
            what = cer[ok];
 
        }
        else {
            what = 1;
            for (i=1;i<=m;i++){
                if (!f[i]){
                    poz = i;
                    f[i] = 1;
                    break;
                }
            }
        }
        sol[poz] = what - 1;
        /// update
 
        for (i=1;i<=n;i++){
            if ((v[poz].first <= v[poz].second && v[poz].first <= i && i <= v[poz].second) ||
                (v[poz].first > v[poz].second && (i >= v[poz].first || i <= v[poz].second))){
                /// i e afectat de interval
                d[i]--;
                if (cer[i] == 0){
                    if (what == 1)
                        cer[i] = 2;
                    else cer[i] = 1;
                }
                else if (cer[i] == 3){}
                else { /// e 1 sau 2 , cere ceva si i se da
                    if (cer[i] == what){
                        cer[i] = 3;
                    }
                }
 
            }
        }
 
    }
    for (i=1;i<=n;i++){
        if (cer[i] != 3){
            fprintf (fout,"impossible");
            return 0;
        }
    }
    for (i=1;i<=m;i++){
        fprintf (fout,"%d",sol[i]);
    }
    return 0;
}

Compilation message

alternating.cpp: In function 'int main()':
alternating.cpp:11:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     fscanf (fin,"%d%d",&n,&m);
     ~~~~~~~^~~~~~~~~~~~~~~~~~
alternating.cpp:13:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         fscanf (fin,"%d%d",&v[i].first,&v[i].second);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alternating.cpp:64:18: warning: 'poz' may be used uninitialized in this function [-Wmaybe-uninitialized]
         sol[poz] = what - 1;
         ~~~~~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 372 KB Output is correct
10 Correct 2 ms 404 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 372 KB Output is correct
32 Correct 0 ms 376 KB Output is correct
33 Correct 2 ms 404 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 348 KB Output is correct
37 Correct 2 ms 404 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 372 KB Output is correct
10 Correct 2 ms 404 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 372 KB Output is correct
32 Correct 0 ms 376 KB Output is correct
33 Correct 2 ms 404 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 348 KB Output is correct
37 Correct 2 ms 404 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 3 ms 376 KB Output is correct
43 Correct 2 ms 376 KB Output is correct
44 Correct 2 ms 384 KB Output is correct
45 Correct 5 ms 376 KB Output is correct
46 Correct 2 ms 376 KB Output is correct
47 Correct 2 ms 296 KB Output is correct
48 Correct 0 ms 364 KB Output is correct
49 Correct 2 ms 376 KB Output is correct
50 Correct 2 ms 372 KB Output is correct
51 Correct 2 ms 376 KB Output is correct
52 Correct 2 ms 376 KB Output is correct
53 Correct 2 ms 372 KB Output is correct
54 Correct 2 ms 380 KB Output is correct
55 Correct 2 ms 376 KB Output is correct
56 Correct 3 ms 376 KB Output is correct
57 Correct 2 ms 348 KB Output is correct
58 Correct 2 ms 368 KB Output is correct
59 Correct 2 ms 380 KB Output is correct
60 Correct 2 ms 372 KB Output is correct
61 Correct 2 ms 348 KB Output is correct
62 Correct 2 ms 376 KB Output is correct
63 Correct 2 ms 376 KB Output is correct
64 Correct 2 ms 376 KB Output is correct
65 Correct 2 ms 376 KB Output is correct
66 Correct 2 ms 348 KB Output is correct
67 Correct 2 ms 376 KB Output is correct
68 Correct 2 ms 364 KB Output is correct
69 Correct 1 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 372 KB Output is correct
10 Correct 2 ms 404 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 372 KB Output is correct
32 Correct 0 ms 376 KB Output is correct
33 Correct 2 ms 404 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 348 KB Output is correct
37 Correct 2 ms 404 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 3 ms 376 KB Output is correct
43 Correct 2 ms 376 KB Output is correct
44 Correct 2 ms 384 KB Output is correct
45 Correct 5 ms 376 KB Output is correct
46 Correct 2 ms 376 KB Output is correct
47 Correct 2 ms 296 KB Output is correct
48 Correct 0 ms 364 KB Output is correct
49 Correct 2 ms 376 KB Output is correct
50 Correct 2 ms 372 KB Output is correct
51 Correct 2 ms 376 KB Output is correct
52 Correct 2 ms 376 KB Output is correct
53 Correct 2 ms 372 KB Output is correct
54 Correct 2 ms 380 KB Output is correct
55 Correct 2 ms 376 KB Output is correct
56 Correct 3 ms 376 KB Output is correct
57 Correct 2 ms 348 KB Output is correct
58 Correct 2 ms 368 KB Output is correct
59 Correct 2 ms 380 KB Output is correct
60 Correct 2 ms 372 KB Output is correct
61 Correct 2 ms 348 KB Output is correct
62 Correct 2 ms 376 KB Output is correct
63 Correct 2 ms 376 KB Output is correct
64 Correct 2 ms 376 KB Output is correct
65 Correct 2 ms 376 KB Output is correct
66 Correct 2 ms 348 KB Output is correct
67 Correct 2 ms 376 KB Output is correct
68 Correct 2 ms 364 KB Output is correct
69 Correct 1 ms 376 KB Output is correct
70 Correct 6 ms 376 KB Output is correct
71 Correct 6 ms 408 KB Output is correct
72 Correct 2 ms 368 KB Output is correct
73 Correct 2 ms 376 KB Output is correct
74 Correct 2 ms 400 KB Output is correct
75 Correct 2 ms 376 KB Output is correct
76 Correct 4 ms 376 KB Output is correct
77 Correct 4 ms 408 KB Output is correct
78 Correct 2 ms 376 KB Output is correct
79 Correct 2 ms 376 KB Output is correct
80 Correct 6 ms 376 KB Output is correct
81 Correct 2 ms 376 KB Output is correct
82 Correct 2 ms 376 KB Output is correct
83 Correct 5 ms 376 KB Output is correct
84 Correct 7 ms 376 KB Output is correct
85 Correct 2 ms 376 KB Output is correct
86 Correct 2 ms 368 KB Output is correct
87 Correct 5 ms 376 KB Output is correct
88 Correct 2 ms 376 KB Output is correct
89 Correct 4 ms 424 KB Output is correct
90 Correct 5 ms 376 KB Output is correct
91 Correct 2 ms 376 KB Output is correct
92 Correct 3 ms 368 KB Output is correct
93 Correct 2 ms 368 KB Output is correct
94 Correct 2 ms 376 KB Output is correct
95 Correct 2 ms 376 KB Output is correct
96 Correct 5 ms 408 KB Output is correct
97 Correct 6 ms 376 KB Output is correct
98 Correct 4 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3020 ms 1108 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 372 KB Output is correct
10 Correct 2 ms 404 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 372 KB Output is correct
32 Correct 0 ms 376 KB Output is correct
33 Correct 2 ms 404 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 348 KB Output is correct
37 Correct 2 ms 404 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 3 ms 376 KB Output is correct
43 Correct 2 ms 376 KB Output is correct
44 Correct 2 ms 384 KB Output is correct
45 Correct 5 ms 376 KB Output is correct
46 Correct 2 ms 376 KB Output is correct
47 Correct 2 ms 296 KB Output is correct
48 Correct 0 ms 364 KB Output is correct
49 Correct 2 ms 376 KB Output is correct
50 Correct 2 ms 372 KB Output is correct
51 Correct 2 ms 376 KB Output is correct
52 Correct 2 ms 376 KB Output is correct
53 Correct 2 ms 372 KB Output is correct
54 Correct 2 ms 380 KB Output is correct
55 Correct 2 ms 376 KB Output is correct
56 Correct 3 ms 376 KB Output is correct
57 Correct 2 ms 348 KB Output is correct
58 Correct 2 ms 368 KB Output is correct
59 Correct 2 ms 380 KB Output is correct
60 Correct 2 ms 372 KB Output is correct
61 Correct 2 ms 348 KB Output is correct
62 Correct 2 ms 376 KB Output is correct
63 Correct 2 ms 376 KB Output is correct
64 Correct 2 ms 376 KB Output is correct
65 Correct 2 ms 376 KB Output is correct
66 Correct 2 ms 348 KB Output is correct
67 Correct 2 ms 376 KB Output is correct
68 Correct 2 ms 364 KB Output is correct
69 Correct 1 ms 376 KB Output is correct
70 Correct 6 ms 376 KB Output is correct
71 Correct 6 ms 408 KB Output is correct
72 Correct 2 ms 368 KB Output is correct
73 Correct 2 ms 376 KB Output is correct
74 Correct 2 ms 400 KB Output is correct
75 Correct 2 ms 376 KB Output is correct
76 Correct 4 ms 376 KB Output is correct
77 Correct 4 ms 408 KB Output is correct
78 Correct 2 ms 376 KB Output is correct
79 Correct 2 ms 376 KB Output is correct
80 Correct 6 ms 376 KB Output is correct
81 Correct 2 ms 376 KB Output is correct
82 Correct 2 ms 376 KB Output is correct
83 Correct 5 ms 376 KB Output is correct
84 Correct 7 ms 376 KB Output is correct
85 Correct 2 ms 376 KB Output is correct
86 Correct 2 ms 368 KB Output is correct
87 Correct 5 ms 376 KB Output is correct
88 Correct 2 ms 376 KB Output is correct
89 Correct 4 ms 424 KB Output is correct
90 Correct 5 ms 376 KB Output is correct
91 Correct 2 ms 376 KB Output is correct
92 Correct 3 ms 368 KB Output is correct
93 Correct 2 ms 368 KB Output is correct
94 Correct 2 ms 376 KB Output is correct
95 Correct 2 ms 376 KB Output is correct
96 Correct 5 ms 408 KB Output is correct
97 Correct 6 ms 376 KB Output is correct
98 Correct 4 ms 348 KB Output is correct
99 Execution timed out 3020 ms 1108 KB Time limit exceeded
100 Halted 0 ms 0 KB -