답안 #635350

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
635350 2022-08-26T06:32:37 Z radal 송금 (JOI19_remittance) C++17
15 / 100
537 ms 344 KB
#include <bits/stdc++.h>
#pragma GCC target("sse,sse2")
#pragma GCC optimize("unroll-loops,O3")
#define rep(i,l,r) for (int i = l; i < r; i++)
#define repr(i,r,l) for (int i = r; i >= l; i--)
#define X first
#define Y second
#define all(x) (x).begin() , (x).end()
#define pb push_back
#define endl '\n'
#define debug(x) cerr << #x << " : " << x << endl;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pll;
constexpr int N = 1e6+20,mod = 1e9+7,inf = 1e9+10;
inline int mkay(int a,int b){
    if (a+b >= mod) return a+b-mod;
    if (a+b < 0) return a+b+mod;
    return a+b;
}
 
inline int poww(int a,int k){
    if (k < 0) return 0;
    int z = 1;
    while (k){
        if (k&1) z = 1ll*z*a%mod;
        a = 1ll*a*a%mod;
        k /= 2;
    } 
    return z; 
}

int a[N],b[N],n,x[N],j,tmp[N];
ll s,s2;
int nxt(int i){
    return ((i == n-1) ? 0 : i+1);
}

bool check(int val){
    s2 = val;
    if (s2 > s) return 0;
    x[j] = val;
    int cur = j;
    do{
        int k = nxt(cur);
        if  (k == j) break;
        if ((a[cur]-b[cur]+x[cur])%2 || a[cur]-b[cur] < -x[cur]){
            return 0;
        }
        x[k] = (a[cur]-b[cur]+x[cur])/2;
        s2 += x[k];
        if (s2 > s) return 0;
        cur = k;
    }while (1);
    if (s != s2) return 0;
    return 1;
}

bool check2(){
    rep(i,0,n) tmp[i] = a[i];
    while (1){
        bool fl = 0;
        rep(i,0,n) fl |= x[i];
        if (!fl) return 1;
        rep(i,0,n){
            int k = nxt(i);
            if (!x[k] || tmp[i] <= 1) continue;
            fl = 0;
            if (tmp[i] >= 2*x[k]){
                tmp[i] -= 2*x[k];
                tmp[k] += 2*x[k];
                x[k] = 0;
            }
            else{
                int cnt = tmp[i]/2;
                tmp[i] -= 2*cnt;
                x[k] -= cnt;
                tmp[k] += cnt;
            }
        }
        if (fl) return 0;
    }
}
int main(){
    ios_base :: sync_with_stdio(0); cin.tie(0);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    cin >> n;
    int mx = -1;
    rep(i,0,n){
        cin >> a[i] >> b[i];
        s += a[i]-b[i];
        if (a[i]-b[i] > mx){
            j = i;
            mx = a[i]-b[i];
        }
    }
    if (s < 0){
        cout << "No";
        return 0;
    }
    j = rng()%n;
    rep(i,0,100000000) if (check(i) && check2()){
        cout << "Yes";
        return 0;
    }
    cout << "No";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 226 ms 340 KB Output is correct
13 Correct 212 ms 340 KB Output is correct
14 Correct 233 ms 344 KB Output is correct
15 Correct 243 ms 340 KB Output is correct
16 Correct 232 ms 340 KB Output is correct
17 Correct 258 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 225 ms 340 KB Output is correct
20 Correct 219 ms 340 KB Output is correct
21 Correct 247 ms 340 KB Output is correct
22 Correct 242 ms 340 KB Output is correct
23 Correct 213 ms 340 KB Output is correct
24 Correct 0 ms 224 KB Output is correct
25 Correct 242 ms 340 KB Output is correct
26 Correct 221 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 218 ms 340 KB Output is correct
31 Correct 238 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 226 ms 340 KB Output is correct
13 Correct 212 ms 340 KB Output is correct
14 Correct 233 ms 344 KB Output is correct
15 Correct 243 ms 340 KB Output is correct
16 Correct 232 ms 340 KB Output is correct
17 Correct 258 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 225 ms 340 KB Output is correct
20 Correct 219 ms 340 KB Output is correct
21 Correct 247 ms 340 KB Output is correct
22 Correct 242 ms 340 KB Output is correct
23 Correct 213 ms 340 KB Output is correct
24 Correct 0 ms 224 KB Output is correct
25 Correct 242 ms 340 KB Output is correct
26 Correct 221 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 218 ms 340 KB Output is correct
31 Correct 238 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Incorrect 537 ms 336 KB Output isn't correct
37 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 226 ms 340 KB Output is correct
13 Correct 212 ms 340 KB Output is correct
14 Correct 233 ms 344 KB Output is correct
15 Correct 243 ms 340 KB Output is correct
16 Correct 232 ms 340 KB Output is correct
17 Correct 258 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 225 ms 340 KB Output is correct
20 Correct 219 ms 340 KB Output is correct
21 Correct 247 ms 340 KB Output is correct
22 Correct 242 ms 340 KB Output is correct
23 Correct 213 ms 340 KB Output is correct
24 Correct 0 ms 224 KB Output is correct
25 Correct 242 ms 340 KB Output is correct
26 Correct 221 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 218 ms 340 KB Output is correct
31 Correct 238 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Incorrect 537 ms 336 KB Output isn't correct
37 Halted 0 ms 0 KB -