# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
321624 | 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 = 1000000000000000000LL;
int n;
lli diff[MAXN];
void impossible()
{
printf("No\n");
exit(0);
}
int main()
{
scanf("%d",&n);
for(int i = 1 ; i <= n ; i++)
{
int a, b;
scanf("%d %d",&a,&b);
diff[i] = a - b;
}
lli xCur = 0;
lli xCross = 0;
for(int i = 1 ; i < n ; i++)
{
lli xNext = diff[i] + xCur;
if( xNext%2 == 1 )
{
if( i >= 62 ) impossible();
xCur++; xNext++;
xCross += (1LL << (i - 1));
}
if( xNext < 0 )
{
if( i >= 62 ) impossible();
lli p = (1LL << (i - 1));
if( -xNext > INF/p ) impossible();
xNext = 0;
xCross += -xNext*p;
}
xCur = xNext/2;
if( xCross >= INF ) impossible();
}
lli s = diff[n] + xCur;
if( s%2 == 0 && s/2 == xCross ) printf("Yes\n");
else impossible();
}
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... |