# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
321628 | Lawliet | Remittance (JOI19_remittance) | C++17 | 1 ms | 384 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
const int MAXN = 1000010;
const lli INF = 5000000000000000000LL;
int n;
lli x[MAXN];
lli diff[MAXN];
lli A[MAXN], B[MAXN];
void impossible()
{
printf("No\n");
exit(0);
}
void addCross(int i, lli qtd)
{
if( i >= 62 ) impossible();
lli p = (1LL << (i - 1));
if( qtd > INF/p ) impossible();
x[i] += qtd; x[n] += qtd*p;
if( x[n] >= INF ) impossible();
for(int j = i - 1 ; j >= 1 ; j--)
x[j] += (1LL << (i - j - 1))*qtd;
}
int main()
{
scanf("%d",&n);
for(int i = 1 ; i <= n ; i++)
{
scanf("%lld %lld",&A[i],&B[i]);
diff[i] = A[i] - B[i];
}
for(int i = 1 ; i < n ; i++)
{
x[i] = diff[i] + x[i - 1];
if( x[i] < 0 ) addCross( i , -x[i] );
if( x[i]%2 == 1 ) addCross( i , 1 );
x[i] = x[i]/2;
}
lli s = diff[n] + x[n - 1];
if( s%2 != 0 || s/2 != x[n] ) impossible();
for(int k = 1 ; k <= 100 ; k++)
{
for(int i = 1 ; i <= n ; i++)
{
lli send = min( x[i] , A[i]/2 );
x[i] -= send; A[i] -= 2*send;
A[(i == n) ? 1 : i + 1] += send;
}
}
for(int i = 1 ; i <= n ; i++)
if( A[i] != B[i] ) impossible();
printf("Yes\n");
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |