답안 #1039740

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1039740 2024-07-31T08:17:28 Z phong 송금 (JOI19_remittance) C++17
100 / 100
523 ms 52308 KB
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

#define ll long long
const int nmax = 1e6 + 5, N = 1e5;
const ll oo = 1e9;
const int lg = 31, M = 2, mod = 1e6;
#define pii pair<ll, ll>
#define fi first
#define se second
#define debug(a, n) for(int i = 1; i <= n; ++i) cout << a[i] << ' '; cout << "\n";
#define endl "\n"
#define task "code"
using namespace std;

int n;
pii a[nmax], b[nmax];
bool check(){
    int bs = 40;
    while(bs--){
        for(int i = 0; i < n; ++i){
            if(a[i].fi > a[i].se){
                ll x = (a[i].fi - a[i].se) / 2;
                a[i].fi -= x * 2;
                a[(i + 1) % n].fi += x;
            }
        }
    }
    bool ok = 1;
    for(int i = 0; i < n;++i){
        ok &= (a[i].fi == a[i].se);
    }
    return ok;

}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
//    freopen(task".inp", "r", stdin);
//    freopen(task".out", "w", stdout);
    cin >> n;
    for(int i = 0; i < n; ++i) cin >> a[i].fi >> a[i].se;
    if(check()) cout << "Yes", exit(0);
    int lc = -1, pc = -1;
    for(int i = 0; i < n; ++i){
        if(a[i].fi > a[i].se && a[i].fi > 1){
            if(lc == -1) lc = i;
            pc = i;
        }
        b[i] = a[i];
    }
    if(lc != -1){
        ll x = (a[lc].fi - a[lc].se + 1) / 2;
        a[lc].fi -= x * 2;
        a[(lc + 1) % n].fi += x;
        if(check()) cout << "Yes", exit(0);
        for(int i = 0; i < n; ++i) a[i] = b[i];
        x = (a[pc].fi - a[pc].se + 1) / 2;
        a[pc].fi -= x * 2;
        a[(pc + 1) % n].fi += x;
        if(check()) cout << "Yes", exit(0);
    }
    cout << "No";
}
/*
3 5
12345678
000
0??
1?0
?11
???

3 1
12345678
???
*/

Compilation message

remittance.cpp:38:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   38 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 0 ms 2392 KB Output is correct
21 Correct 1 ms 2648 KB Output is correct
22 Correct 0 ms 2392 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 0 ms 2396 KB Output is correct
26 Correct 0 ms 2396 KB Output is correct
27 Correct 0 ms 2396 KB Output is correct
28 Correct 0 ms 2396 KB Output is correct
29 Correct 0 ms 2396 KB Output is correct
30 Correct 1 ms 2392 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 0 ms 2516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 0 ms 2392 KB Output is correct
21 Correct 1 ms 2648 KB Output is correct
22 Correct 0 ms 2392 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 0 ms 2396 KB Output is correct
26 Correct 0 ms 2396 KB Output is correct
27 Correct 0 ms 2396 KB Output is correct
28 Correct 0 ms 2396 KB Output is correct
29 Correct 0 ms 2396 KB Output is correct
30 Correct 1 ms 2392 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 0 ms 2516 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 0 ms 2396 KB Output is correct
35 Correct 0 ms 2396 KB Output is correct
36 Correct 0 ms 2392 KB Output is correct
37 Correct 1 ms 2392 KB Output is correct
38 Correct 0 ms 2396 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 0 ms 2396 KB Output is correct
43 Correct 1 ms 2396 KB Output is correct
44 Correct 0 ms 2396 KB Output is correct
45 Correct 0 ms 2396 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Correct 0 ms 2396 KB Output is correct
48 Correct 1 ms 2396 KB Output is correct
49 Correct 0 ms 2396 KB Output is correct
50 Correct 1 ms 2396 KB Output is correct
51 Correct 1 ms 2396 KB Output is correct
52 Correct 1 ms 2396 KB Output is correct
53 Correct 0 ms 2396 KB Output is correct
54 Correct 0 ms 2396 KB Output is correct
55 Correct 0 ms 2396 KB Output is correct
56 Correct 0 ms 2396 KB Output is correct
57 Correct 0 ms 2396 KB Output is correct
58 Correct 0 ms 2396 KB Output is correct
59 Correct 0 ms 2396 KB Output is correct
60 Correct 0 ms 2396 KB Output is correct
61 Correct 0 ms 2508 KB Output is correct
62 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 0 ms 2392 KB Output is correct
21 Correct 1 ms 2648 KB Output is correct
22 Correct 0 ms 2392 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 0 ms 2396 KB Output is correct
26 Correct 0 ms 2396 KB Output is correct
27 Correct 0 ms 2396 KB Output is correct
28 Correct 0 ms 2396 KB Output is correct
29 Correct 0 ms 2396 KB Output is correct
30 Correct 1 ms 2392 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 0 ms 2516 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 0 ms 2396 KB Output is correct
35 Correct 0 ms 2396 KB Output is correct
36 Correct 0 ms 2392 KB Output is correct
37 Correct 1 ms 2392 KB Output is correct
38 Correct 0 ms 2396 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 0 ms 2396 KB Output is correct
43 Correct 1 ms 2396 KB Output is correct
44 Correct 0 ms 2396 KB Output is correct
45 Correct 0 ms 2396 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Correct 0 ms 2396 KB Output is correct
48 Correct 1 ms 2396 KB Output is correct
49 Correct 0 ms 2396 KB Output is correct
50 Correct 1 ms 2396 KB Output is correct
51 Correct 1 ms 2396 KB Output is correct
52 Correct 1 ms 2396 KB Output is correct
53 Correct 0 ms 2396 KB Output is correct
54 Correct 0 ms 2396 KB Output is correct
55 Correct 0 ms 2396 KB Output is correct
56 Correct 0 ms 2396 KB Output is correct
57 Correct 0 ms 2396 KB Output is correct
58 Correct 0 ms 2396 KB Output is correct
59 Correct 0 ms 2396 KB Output is correct
60 Correct 0 ms 2396 KB Output is correct
61 Correct 0 ms 2508 KB Output is correct
62 Correct 1 ms 2396 KB Output is correct
63 Correct 523 ms 51028 KB Output is correct
64 Correct 97 ms 20932 KB Output is correct
65 Correct 239 ms 50628 KB Output is correct
66 Correct 96 ms 21072 KB Output is correct
67 Correct 107 ms 22348 KB Output is correct
68 Correct 106 ms 24656 KB Output is correct
69 Correct 253 ms 51028 KB Output is correct
70 Correct 102 ms 35456 KB Output is correct
71 Correct 160 ms 36928 KB Output is correct
72 Correct 176 ms 39248 KB Output is correct
73 Correct 304 ms 51128 KB Output is correct
74 Correct 99 ms 35664 KB Output is correct
75 Correct 157 ms 36816 KB Output is correct
76 Correct 174 ms 39252 KB Output is correct
77 Correct 223 ms 51024 KB Output is correct
78 Correct 179 ms 43332 KB Output is correct
79 Correct 179 ms 43212 KB Output is correct
80 Correct 219 ms 43348 KB Output is correct
81 Correct 185 ms 43344 KB Output is correct
82 Correct 144 ms 35520 KB Output is correct
83 Correct 91 ms 35664 KB Output is correct
84 Correct 91 ms 21076 KB Output is correct
85 Correct 246 ms 52048 KB Output is correct
86 Correct 308 ms 52308 KB Output is correct
87 Correct 185 ms 44356 KB Output is correct
88 Correct 210 ms 44628 KB Output is correct