답안 #223590

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
223590 2020-04-15T14:22:39 Z spacewalker 송금 (JOI19_remittance) C++14
100 / 100
588 ms 28024 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;

ll FMOD(ll x) {
	return (x % MOD + MOD) % MOD;
}

// if X, the next number will be
// 2X - peak

void answer(bool yn) {
	if (yn) printf("Yes\n");
	else printf("No\n");
	exit(0);
}

ll modexp(ll b, ll e) {
	if (e == 0) return 1;
	else return (e & 1 ? b : 1) * modexp(b * b % MOD, e/2) % MOD;
}

ll modinv(ll x) {return modexp(x, MOD - 2);}

int main() {
	int n; scanf("%d", &n);
	vector<ll> before(n), after(n);
	for (int i = 0; i < n; ++i) scanf("%lld %lld", &before[i], &after[i]);
	ll sanity = 0;
	for (int i = 0; i < n; ++i) if (before[i] != after[i]) ++sanity;
	if (sanity == 0) answer(true);
	sanity = 0;
	for (int x : after) sanity += x;
	if (sanity == 0) answer(false);
	vector<ll> flows(n);
	for (int i = 0; i < n; ++i) flows[n-1] = FMOD(flows[n-1] + modexp(2, i) * (before[i] - after[i]));
	flows[n-1] = FMOD(flows[n-1] * modinv(FMOD(modexp(2, n) - 1)));
	for (int i = n - 2; i >= 0; --i) flows[i] = FMOD(2*flows[i+1] - (before[i + 1] - after[i + 1]));
	for (int i = 0; i < n; ++i) {
		if (2*flows[i] - flows[(i + n - 1) % n] != before[i] - after[i]) answer(false);
	}
//	for (int i = 0; i < n; ++i) printf("%d flow %lld\n", i, flows[i]);
	answer(true);
	return 0;

}

Compilation message

remittance.cpp: In function 'int main()':
remittance.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int n; scanf("%d", &n);
         ~~~~~^~~~~~~~~~
remittance.cpp:30:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 0; i < n; ++i) scanf("%lld %lld", &before[i], &after[i]);
                              ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 256 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 4 ms 256 KB Output is correct
16 Correct 5 ms 256 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 4 ms 256 KB Output is correct
19 Correct 4 ms 256 KB Output is correct
20 Correct 5 ms 256 KB Output is correct
21 Correct 5 ms 256 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 4 ms 256 KB Output is correct
24 Correct 5 ms 256 KB Output is correct
25 Correct 5 ms 256 KB Output is correct
26 Correct 4 ms 256 KB Output is correct
27 Correct 5 ms 256 KB Output is correct
28 Correct 5 ms 256 KB Output is correct
29 Correct 5 ms 256 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 4 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 256 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 4 ms 256 KB Output is correct
16 Correct 5 ms 256 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 4 ms 256 KB Output is correct
19 Correct 4 ms 256 KB Output is correct
20 Correct 5 ms 256 KB Output is correct
21 Correct 5 ms 256 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 4 ms 256 KB Output is correct
24 Correct 5 ms 256 KB Output is correct
25 Correct 5 ms 256 KB Output is correct
26 Correct 4 ms 256 KB Output is correct
27 Correct 5 ms 256 KB Output is correct
28 Correct 5 ms 256 KB Output is correct
29 Correct 5 ms 256 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 4 ms 256 KB Output is correct
33 Correct 4 ms 384 KB Output is correct
34 Correct 5 ms 256 KB Output is correct
35 Correct 5 ms 256 KB Output is correct
36 Correct 5 ms 256 KB Output is correct
37 Correct 5 ms 256 KB Output is correct
38 Correct 4 ms 256 KB Output is correct
39 Correct 5 ms 256 KB Output is correct
40 Correct 4 ms 256 KB Output is correct
41 Correct 5 ms 256 KB Output is correct
42 Correct 5 ms 256 KB Output is correct
43 Correct 4 ms 256 KB Output is correct
44 Correct 5 ms 256 KB Output is correct
45 Correct 5 ms 256 KB Output is correct
46 Correct 5 ms 256 KB Output is correct
47 Correct 5 ms 256 KB Output is correct
48 Correct 5 ms 256 KB Output is correct
49 Correct 5 ms 256 KB Output is correct
50 Correct 5 ms 256 KB Output is correct
51 Correct 4 ms 256 KB Output is correct
52 Correct 5 ms 256 KB Output is correct
53 Correct 5 ms 256 KB Output is correct
54 Correct 5 ms 256 KB Output is correct
55 Correct 5 ms 256 KB Output is correct
56 Correct 4 ms 256 KB Output is correct
57 Correct 5 ms 256 KB Output is correct
58 Correct 5 ms 384 KB Output is correct
59 Correct 5 ms 256 KB Output is correct
60 Correct 5 ms 256 KB Output is correct
61 Correct 5 ms 256 KB Output is correct
62 Correct 4 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 256 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 4 ms 256 KB Output is correct
16 Correct 5 ms 256 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 4 ms 256 KB Output is correct
19 Correct 4 ms 256 KB Output is correct
20 Correct 5 ms 256 KB Output is correct
21 Correct 5 ms 256 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 4 ms 256 KB Output is correct
24 Correct 5 ms 256 KB Output is correct
25 Correct 5 ms 256 KB Output is correct
26 Correct 4 ms 256 KB Output is correct
27 Correct 5 ms 256 KB Output is correct
28 Correct 5 ms 256 KB Output is correct
29 Correct 5 ms 256 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 4 ms 256 KB Output is correct
33 Correct 4 ms 384 KB Output is correct
34 Correct 5 ms 256 KB Output is correct
35 Correct 5 ms 256 KB Output is correct
36 Correct 5 ms 256 KB Output is correct
37 Correct 5 ms 256 KB Output is correct
38 Correct 4 ms 256 KB Output is correct
39 Correct 5 ms 256 KB Output is correct
40 Correct 4 ms 256 KB Output is correct
41 Correct 5 ms 256 KB Output is correct
42 Correct 5 ms 256 KB Output is correct
43 Correct 4 ms 256 KB Output is correct
44 Correct 5 ms 256 KB Output is correct
45 Correct 5 ms 256 KB Output is correct
46 Correct 5 ms 256 KB Output is correct
47 Correct 5 ms 256 KB Output is correct
48 Correct 5 ms 256 KB Output is correct
49 Correct 5 ms 256 KB Output is correct
50 Correct 5 ms 256 KB Output is correct
51 Correct 4 ms 256 KB Output is correct
52 Correct 5 ms 256 KB Output is correct
53 Correct 5 ms 256 KB Output is correct
54 Correct 5 ms 256 KB Output is correct
55 Correct 5 ms 256 KB Output is correct
56 Correct 4 ms 256 KB Output is correct
57 Correct 5 ms 256 KB Output is correct
58 Correct 5 ms 384 KB Output is correct
59 Correct 5 ms 256 KB Output is correct
60 Correct 5 ms 256 KB Output is correct
61 Correct 5 ms 256 KB Output is correct
62 Correct 4 ms 256 KB Output is correct
63 Correct 577 ms 24336 KB Output is correct
64 Correct 392 ms 27768 KB Output is correct
65 Correct 588 ms 24056 KB Output is correct
66 Correct 391 ms 27896 KB Output is correct
67 Correct 407 ms 27896 KB Output is correct
68 Correct 446 ms 27384 KB Output is correct
69 Correct 575 ms 24056 KB Output is correct
70 Correct 385 ms 27768 KB Output is correct
71 Correct 397 ms 27896 KB Output is correct
72 Correct 431 ms 27256 KB Output is correct
73 Correct 569 ms 24184 KB Output is correct
74 Correct 385 ms 27768 KB Output is correct
75 Correct 409 ms 28024 KB Output is correct
76 Correct 425 ms 27256 KB Output is correct
77 Correct 573 ms 24060 KB Output is correct
78 Correct 263 ms 19168 KB Output is correct
79 Correct 277 ms 19064 KB Output is correct
80 Correct 472 ms 27000 KB Output is correct
81 Correct 463 ms 26872 KB Output is correct
82 Correct 170 ms 19832 KB Output is correct
83 Correct 366 ms 27896 KB Output is correct
84 Correct 187 ms 19960 KB Output is correct
85 Correct 531 ms 24056 KB Output is correct
86 Correct 541 ms 24056 KB Output is correct
87 Correct 214 ms 18808 KB Output is correct
88 Correct 453 ms 26744 KB Output is correct