답안 #165337

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
165337 2019-11-26T12:24:16 Z Akashi Coin Collecting (JOI19_ho_t4) C++14
100 / 100
98 ms 7460 KB
#include <bits/stdc++.h>
using namespace std;

struct coins{
    int x, y;
    bool operator < (const coins &aux)const{
        if(x != aux.x) return x < aux.x;
        return y < aux.y;
    }
};

coins a[200005];

int n;
queue <int> coins[3], cell[3];

int main()
{
//    freopen("1.in", "r", stdin);

    scanf("%d", &n);

    long long Sol = 0;
    for(int i = 1; i <= 2 * n ; ++i){
        scanf("%d%d", &a[i].x, &a[i].y);

        if(a[i].x < 1) Sol = Sol + (1 - a[i].x), a[i].x = 1;
        if(a[i].x > n) Sol = Sol + (a[i].x - n), a[i].x = n;

        if(a[i].y < 1) Sol = Sol + (1 - a[i].y), a[i].y = 1;
        if(a[i].y > 2) Sol = Sol + (a[i].y - 2), a[i].y = 2;
    }

    sort(a + 1, a + 2 * n + 1);

    int j = 1;
    for(int i = 1; i <= n ; ++i){
        while(a[j].x <= i && j <= 2 * n) coins[a[j].y].push(a[j].x), ++j;


        cell[1].push(i);
        cell[2].push(i);

        while(!cell[1].empty() && !coins[1].empty()){
            Sol = Sol + abs(cell[1].front() - coins[1].front());
            cell[1].pop();
            coins[1].pop();
        }
        ///
        while(!cell[2].empty() && !coins[2].empty()){
            Sol = Sol + abs(cell[2].front() - coins[2].front());
            cell[2].pop();
            coins[2].pop();
        }
        ///
        while(!cell[1].empty() && !coins[2].empty()){
            Sol = Sol + abs(cell[1].front() - coins[2].front()) + 1;
            cell[1].pop();
            coins[2].pop();
        }
        ///
        while(!cell[2].empty() && !coins[1].empty()){
            Sol = Sol + abs(cell[2].front() - coins[1].front()) + 1;
            cell[2].pop();
            coins[1].pop();
        }
    }

    printf("%lld", Sol);

    return 0;
}














Compilation message

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
joi2019_ho_t4.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &a[i].x, &a[i].y);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 404 KB Output is correct
17 Correct 2 ms 256 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 256 KB Output is correct
21 Correct 2 ms 256 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 256 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 256 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 380 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 3 ms 256 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 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 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 404 KB Output is correct
17 Correct 2 ms 256 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 256 KB Output is correct
21 Correct 2 ms 256 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 256 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 256 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 380 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 3 ms 256 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 4 ms 376 KB Output is correct
35 Correct 3 ms 376 KB Output is correct
36 Correct 3 ms 376 KB Output is correct
37 Correct 3 ms 376 KB Output is correct
38 Correct 3 ms 376 KB Output is correct
39 Correct 3 ms 376 KB Output is correct
40 Correct 3 ms 376 KB Output is correct
41 Correct 3 ms 376 KB Output is correct
42 Correct 3 ms 376 KB Output is correct
43 Correct 3 ms 376 KB Output is correct
44 Correct 3 ms 376 KB Output is correct
45 Correct 3 ms 376 KB Output is correct
46 Correct 3 ms 376 KB Output is correct
47 Correct 3 ms 380 KB Output is correct
48 Correct 3 ms 376 KB Output is correct
49 Correct 3 ms 376 KB Output is correct
50 Correct 3 ms 376 KB Output is correct
51 Correct 3 ms 376 KB Output is correct
52 Correct 3 ms 376 KB Output is correct
53 Correct 3 ms 296 KB Output is correct
54 Correct 3 ms 376 KB Output is correct
55 Correct 3 ms 376 KB Output is correct
56 Correct 3 ms 376 KB Output is correct
57 Correct 3 ms 376 KB Output is correct
58 Correct 3 ms 376 KB Output is correct
59 Correct 3 ms 376 KB Output is correct
60 Correct 3 ms 376 KB Output is correct
61 Correct 3 ms 376 KB Output is correct
62 Correct 3 ms 504 KB Output is correct
63 Correct 3 ms 376 KB Output is correct
64 Correct 3 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 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 404 KB Output is correct
17 Correct 2 ms 256 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 256 KB Output is correct
21 Correct 2 ms 256 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 256 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 256 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 380 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 3 ms 256 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 4 ms 376 KB Output is correct
35 Correct 3 ms 376 KB Output is correct
36 Correct 3 ms 376 KB Output is correct
37 Correct 3 ms 376 KB Output is correct
38 Correct 3 ms 376 KB Output is correct
39 Correct 3 ms 376 KB Output is correct
40 Correct 3 ms 376 KB Output is correct
41 Correct 3 ms 376 KB Output is correct
42 Correct 3 ms 376 KB Output is correct
43 Correct 3 ms 376 KB Output is correct
44 Correct 3 ms 376 KB Output is correct
45 Correct 3 ms 376 KB Output is correct
46 Correct 3 ms 376 KB Output is correct
47 Correct 3 ms 380 KB Output is correct
48 Correct 3 ms 376 KB Output is correct
49 Correct 3 ms 376 KB Output is correct
50 Correct 3 ms 376 KB Output is correct
51 Correct 3 ms 376 KB Output is correct
52 Correct 3 ms 376 KB Output is correct
53 Correct 3 ms 296 KB Output is correct
54 Correct 3 ms 376 KB Output is correct
55 Correct 3 ms 376 KB Output is correct
56 Correct 3 ms 376 KB Output is correct
57 Correct 3 ms 376 KB Output is correct
58 Correct 3 ms 376 KB Output is correct
59 Correct 3 ms 376 KB Output is correct
60 Correct 3 ms 376 KB Output is correct
61 Correct 3 ms 376 KB Output is correct
62 Correct 3 ms 504 KB Output is correct
63 Correct 3 ms 376 KB Output is correct
64 Correct 3 ms 376 KB Output is correct
65 Correct 70 ms 3412 KB Output is correct
66 Correct 69 ms 7460 KB Output is correct
67 Correct 98 ms 5112 KB Output is correct
68 Correct 92 ms 5112 KB Output is correct
69 Correct 92 ms 5112 KB Output is correct
70 Correct 92 ms 5112 KB Output is correct
71 Correct 91 ms 5240 KB Output is correct
72 Correct 70 ms 6264 KB Output is correct
73 Correct 70 ms 6728 KB Output is correct
74 Correct 85 ms 5624 KB Output is correct
75 Correct 74 ms 5624 KB Output is correct
76 Correct 77 ms 5496 KB Output is correct
77 Correct 76 ms 5624 KB Output is correct
78 Correct 83 ms 5496 KB Output is correct
79 Correct 77 ms 5624 KB Output is correct
80 Correct 78 ms 5624 KB Output is correct
81 Correct 76 ms 5448 KB Output is correct
82 Correct 82 ms 5192 KB Output is correct
83 Correct 79 ms 5480 KB Output is correct
84 Correct 83 ms 5240 KB Output is correct
85 Correct 83 ms 5112 KB Output is correct
86 Correct 91 ms 5112 KB Output is correct
87 Correct 87 ms 5244 KB Output is correct
88 Correct 90 ms 5112 KB Output is correct
89 Correct 93 ms 5248 KB Output is correct
90 Correct 92 ms 5112 KB Output is correct
91 Correct 96 ms 5112 KB Output is correct
92 Correct 90 ms 5240 KB Output is correct
93 Correct 90 ms 5112 KB Output is correct
94 Correct 90 ms 5072 KB Output is correct
95 Correct 89 ms 5112 KB Output is correct
96 Correct 78 ms 6152 KB Output is correct
97 Correct 79 ms 6264 KB Output is correct
98 Correct 79 ms 5624 KB Output is correct
99 Correct 82 ms 5664 KB Output is correct
100 Correct 82 ms 5752 KB Output is correct
101 Correct 79 ms 6008 KB Output is correct
102 Correct 81 ms 5752 KB Output is correct
103 Correct 81 ms 5624 KB Output is correct