답안 #321629

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
321629 2020-11-13T00:15:30 Z Lawliet 송금 (JOI19_remittance) C++17
15 / 100
11 ms 364 KB
#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 <= 100000 ; 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

remittance.cpp: In function 'int main()':
remittance.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   38 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
remittance.cpp:42:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   42 |   scanf("%lld %lld",&A[i],&B[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 3 ms 364 KB Output is correct
6 Correct 4 ms 364 KB Output is correct
7 Correct 4 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 3 ms 364 KB Output is correct
10 Correct 4 ms 364 KB Output is correct
11 Correct 4 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 0 ms 364 KB Output is correct
18 Correct 4 ms 364 KB Output is correct
19 Correct 0 ms 364 KB Output is correct
20 Correct 4 ms 364 KB Output is correct
21 Correct 4 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 4 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 4 ms 364 KB Output is correct
27 Correct 0 ms 364 KB Output is correct
28 Correct 4 ms 364 KB Output is correct
29 Correct 4 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 4 ms 364 KB Output is correct
32 Correct 4 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 3 ms 364 KB Output is correct
6 Correct 4 ms 364 KB Output is correct
7 Correct 4 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 3 ms 364 KB Output is correct
10 Correct 4 ms 364 KB Output is correct
11 Correct 4 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 0 ms 364 KB Output is correct
18 Correct 4 ms 364 KB Output is correct
19 Correct 0 ms 364 KB Output is correct
20 Correct 4 ms 364 KB Output is correct
21 Correct 4 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 4 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 4 ms 364 KB Output is correct
27 Correct 0 ms 364 KB Output is correct
28 Correct 4 ms 364 KB Output is correct
29 Correct 4 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 4 ms 364 KB Output is correct
32 Correct 4 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 11 ms 364 KB Output is correct
35 Correct 11 ms 364 KB Output is correct
36 Incorrect 1 ms 364 KB Output isn't correct
37 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 3 ms 364 KB Output is correct
6 Correct 4 ms 364 KB Output is correct
7 Correct 4 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 3 ms 364 KB Output is correct
10 Correct 4 ms 364 KB Output is correct
11 Correct 4 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 0 ms 364 KB Output is correct
18 Correct 4 ms 364 KB Output is correct
19 Correct 0 ms 364 KB Output is correct
20 Correct 4 ms 364 KB Output is correct
21 Correct 4 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 4 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 4 ms 364 KB Output is correct
27 Correct 0 ms 364 KB Output is correct
28 Correct 4 ms 364 KB Output is correct
29 Correct 4 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 4 ms 364 KB Output is correct
32 Correct 4 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 11 ms 364 KB Output is correct
35 Correct 11 ms 364 KB Output is correct
36 Incorrect 1 ms 364 KB Output isn't correct
37 Halted 0 ms 0 KB -