Submission #552043

# Submission time Handle Problem Language Result Execution time Memory
552043 2022-04-22T09:19:12 Z cheetose Remittance (JOI19_remittance) C++17
100 / 100
285 ms 52044 KB
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 1987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a))
#define MEM_1(a) memset((a),-1,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define COMPRESS(a) sort(ALL(a));a.resize(unique(ALL(a))-a.begin())
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<ld> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 998244353;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
int ddx[] = { -1,-2,1,-2,2,-1,2,1 }, ddy[] = { -2,-1,-2,1,-1,2,1,2 };

ll A[1000000],B[1000000],C[1000000];
ll t[1000000];
bool chk[1000000];
int main(){
	int n;
	scanf("%d",&n);
	fup(i,0,n-1,1){
		scanf("%lld%lld",A+i,B+i);
		C[i]=B[i]-A[i];
	}
	ll l=0,r=1e9,res=-1;
	while(l<=r){
		ll k=l+r>>1;
		t[0]=k;
		t[n-1]=2*k+C[0];
		int tt=0;
		if(t[n-1]<0){
			tt=-1;
		}
		if(t[n-1]>1e9){
			tt=1;
		}
		if(!tt){
			fdn(i,n-2,1,1){
				t[i]=t[i+1]*2+C[i+1];
				if(t[i]<0){
					tt=-1;
					break;
				}
				if(t[i]>1e9){
					tt=1;
					break;
				}
			}
			if(!tt){
				ll r=t[1]*2+C[1];
				if(r<t[0])tt=-1;
				else if(r>t[0])tt=1;
			}
		}
		if(tt==0){
			res=k;
			break;
		}
		if(tt<0)l=k+1;
		else r=k-1;
	}
	if(res<0)return !printf("No\n");
	int tt=30;
	while(tt--){
		fup(i,0,n-1,1){
			if(!t[i])continue;
			int j=i+1;
			if(j==n)j=0;
			ll mn=min(t[i],A[i]>>1);
			A[i]-=2*mn;
			t[i]-=mn;
			A[j]+=mn;
		}
	}
	fup(i,0,n-1,1){
		if(A[i]^B[i])return !printf("No\n");
	}
	puts("Yes");
}

Compilation message

remittance.cpp: In function 'int main()':
remittance.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
remittance.cpp:49:2: note: in expansion of macro 'fup'
   49 |  fup(i,0,n-1,1){
      |  ^~~
remittance.cpp:55:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   55 |   ll k=l+r>>1;
      |        ~^~
remittance.cpp:11:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   11 | #define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
      |                              ^
remittance.cpp:66:4: note: in expansion of macro 'fdn'
   66 |    fdn(i,n-2,1,1){
      |    ^~~
remittance.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
remittance.cpp:93:3: note: in expansion of macro 'fup'
   93 |   fup(i,0,n-1,1){
      |   ^~~
remittance.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
remittance.cpp:103:2: note: in expansion of macro 'fup'
  103 |  fup(i,0,n-1,1){
      |  ^~~
remittance.cpp:48:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
remittance.cpp:50:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |   scanf("%lld%lld",A+i,B+i);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 308 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 308 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 0 ms 312 KB Output is correct
30 Correct 1 ms 308 KB Output is correct
31 Correct 1 ms 308 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 308 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 308 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 0 ms 312 KB Output is correct
30 Correct 1 ms 308 KB Output is correct
31 Correct 1 ms 308 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 308 KB Output is correct
35 Correct 1 ms 308 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 308 KB Output is correct
38 Correct 1 ms 304 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 308 KB Output is correct
47 Correct 0 ms 308 KB Output is correct
48 Correct 1 ms 304 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 312 KB Output is correct
52 Correct 1 ms 308 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 308 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 0 ms 308 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 308 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 308 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 0 ms 312 KB Output is correct
30 Correct 1 ms 308 KB Output is correct
31 Correct 1 ms 308 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 308 KB Output is correct
35 Correct 1 ms 308 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 308 KB Output is correct
38 Correct 1 ms 304 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 308 KB Output is correct
47 Correct 0 ms 308 KB Output is correct
48 Correct 1 ms 304 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 312 KB Output is correct
52 Correct 1 ms 308 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 308 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 0 ms 308 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 229 ms 43040 KB Output is correct
64 Correct 196 ms 35572 KB Output is correct
65 Correct 243 ms 50524 KB Output is correct
66 Correct 174 ms 35512 KB Output is correct
67 Correct 177 ms 36792 KB Output is correct
68 Correct 184 ms 39264 KB Output is correct
69 Correct 247 ms 50932 KB Output is correct
70 Correct 134 ms 27732 KB Output is correct
71 Correct 154 ms 35148 KB Output is correct
72 Correct 146 ms 33720 KB Output is correct
73 Correct 199 ms 44876 KB Output is correct
74 Correct 135 ms 33108 KB Output is correct
75 Correct 143 ms 35876 KB Output is correct
76 Correct 144 ms 37816 KB Output is correct
77 Correct 209 ms 50844 KB Output is correct
78 Correct 273 ms 43212 KB Output is correct
79 Correct 154 ms 35532 KB Output is correct
80 Correct 195 ms 43308 KB Output is correct
81 Correct 152 ms 35852 KB Output is correct
82 Correct 258 ms 35512 KB Output is correct
83 Correct 115 ms 27672 KB Output is correct
84 Correct 178 ms 35516 KB Output is correct
85 Correct 243 ms 52044 KB Output is correct
86 Correct 197 ms 45688 KB Output is correct
87 Correct 285 ms 44428 KB Output is correct
88 Correct 206 ms 44292 KB Output is correct