#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const double PI = 4 * atan(1);
#define sz(x) (int)(x).size()
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair <int, int>
#define vi vector<int>
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define vpi vector<pair<int, int>>
#define vpd vector<pair<double, double>>
#define pd pair<double, double>
#define f0r(i,a) for(int i=0;i<a;i++)
#define f1r(i,a,b) for(int i=a;i<b;i++)
template<typename A, typename B> ostream& operator <<(ostream &cout, pair< A, B> const &p) {return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator <<(ostream &cout, vector<A> const &v){
cout <<"["; for(int i = 0; i<v.size(); i++) {if(i) cout <<", "; cout << v[i];} return cout << "]";
}
void fast_io(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
}
void io(string taskname){
string fin = taskname + ".in";
string fout = taskname + ".out";
const char* FIN = fin.c_str();
const char* FOUT = fout.c_str();
freopen(FIN, "r", stdin);
freopen(FOUT, "w", stdout);
fast_io();
}
const int MAX = 1e6 + 6;
const ll MOD = 67280421310721;
vector<ll> a;
vector<ll> d;
ll po[MAX];
inline ll neg(ll x, ll mod){
return mod - x;
}
inline ll fix(ll x, ll mod){
x = x%mod;
x = (x+mod)%mod;
return x;
}
///use mods less than 1e9 + 7
int n;
long long mulmod(long long a,
long long b,
long long mod)
{
long long res = 0; // Initialize result
// Update a if it is more than
// or equal to mod
a %= mod;
while (b)
{
// If b is odd, add a with result
if (b & 1)
res = (res + a) % mod;
// Here we assume that doing 2*a
// doesn't cause overflow
a = (2 * a) % mod;
b >>= 1; // b = b / 2
}
return res;
}
ll modInverse(ll a, ll m)
{
ll m0 = m;
ll y = 0, x = 1;
if (m == 1)
return 0;
while (a > 1)
{
// q is quotient
ll q = a / m;
ll t = m;
// m is remainder now, process same as
// Euclid's algo
m = a % m, a = t;
t = y;
// Update y and x
y = x - q * y;
x = t;
}
// Make x positive
if (x < 0)
x += m0;
return x;
}
ll check(ll mod){
f0r(i, MAX){
if(i == 0) po[i] = 1;
else{
po[i] = mulmod(po[i-1], 2, mod);
// po[i] %= mod;
}
}
ll rhs = 0;
for(int i = n-1; i>= 0; i--){
// cout << po[i] << " " << fix(d[i], mod) + mod << " " << d[i] << endl;
ll add = mulmod(po[i], fix(d[i], mod), mod);
rhs += add;
// cout << add << endl;
if(rhs>=mod)rhs-=mod;
}
// cout << rhs - mod << endl;
ll x = mulmod(modInverse(fix(neg(po[n]-1, mod), mod), mod),rhs, mod);
return (x%mod);
}
vector<ll> times;
int good = 0;
void upd(int id, int val){
if(a[id]>= 2){
if(a[id] + val<2){
good--;
}
}
else{
if(a[id] + val >= 2) good++;
}
a[id] += val;
}
int main(){
fast_io();
cin >> n;
int cnt = 0;
f0r(i, n){
ll ai, bi;
cin >> ai >> bi;
a.eb(ai);
cnt += (bi == 0);
d.eb(bi - ai);
}
if(cnt == n){
cnt = 0;
f0r(i, n) cnt += (a[i] == 0);
if(cnt == n)cout << "Yes" << endl;
else cout << "No" <<endl;
return 0;
}
// cout << d << endl;
ll x = check(MOD);
times.eb(x);
int cur = n-1;
f0r(i, n-1){
ll val = times[sz(times) - 1]*2 + d[cur];
times.eb(val);
cur--;
}
reverse(all(times));
//cout << times << endl;
f0r(i, n){
int j = (i+1)%n;
if(times[i] != times[j]*2 + d[j]){
cout << "No" << endl;
return 0;
}
if(fix(times[i], MOD) >= 1e12 || times[i]<0){
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
}
Compilation message
remittance.cpp:1:0: warning: ignoring #pragma comment [-Wunknown-pragmas]
#pragma comment(linker, "/stack:200000000")
remittance.cpp: In function 'void io(std::__cxx11::string)':
remittance.cpp:50:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(FIN, "r", stdin);
~~~~~~~^~~~~~~~~~~~~~~~~
remittance.cpp:51:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(FOUT, "w", stdout);
~~~~~~~^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
8184 KB |
Output is correct |
2 |
Correct |
47 ms |
8188 KB |
Output is correct |
3 |
Correct |
49 ms |
8184 KB |
Output is correct |
4 |
Correct |
46 ms |
8184 KB |
Output is correct |
5 |
Correct |
46 ms |
8184 KB |
Output is correct |
6 |
Correct |
47 ms |
8184 KB |
Output is correct |
7 |
Correct |
47 ms |
8184 KB |
Output is correct |
8 |
Correct |
53 ms |
8184 KB |
Output is correct |
9 |
Correct |
50 ms |
8168 KB |
Output is correct |
10 |
Correct |
47 ms |
8184 KB |
Output is correct |
11 |
Correct |
46 ms |
8184 KB |
Output is correct |
12 |
Correct |
47 ms |
8168 KB |
Output is correct |
13 |
Correct |
46 ms |
8184 KB |
Output is correct |
14 |
Correct |
49 ms |
8148 KB |
Output is correct |
15 |
Correct |
47 ms |
8168 KB |
Output is correct |
16 |
Correct |
49 ms |
8156 KB |
Output is correct |
17 |
Correct |
47 ms |
8188 KB |
Output is correct |
18 |
Correct |
47 ms |
8200 KB |
Output is correct |
19 |
Correct |
47 ms |
8184 KB |
Output is correct |
20 |
Correct |
3 ms |
376 KB |
Output is correct |
21 |
Correct |
3 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
48 ms |
8216 KB |
Output is correct |
25 |
Correct |
47 ms |
8188 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
47 ms |
8212 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
29 |
Correct |
47 ms |
8184 KB |
Output is correct |
30 |
Correct |
47 ms |
8156 KB |
Output is correct |
31 |
Correct |
2 ms |
376 KB |
Output is correct |
32 |
Correct |
47 ms |
8156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
8184 KB |
Output is correct |
2 |
Correct |
47 ms |
8188 KB |
Output is correct |
3 |
Correct |
49 ms |
8184 KB |
Output is correct |
4 |
Correct |
46 ms |
8184 KB |
Output is correct |
5 |
Correct |
46 ms |
8184 KB |
Output is correct |
6 |
Correct |
47 ms |
8184 KB |
Output is correct |
7 |
Correct |
47 ms |
8184 KB |
Output is correct |
8 |
Correct |
53 ms |
8184 KB |
Output is correct |
9 |
Correct |
50 ms |
8168 KB |
Output is correct |
10 |
Correct |
47 ms |
8184 KB |
Output is correct |
11 |
Correct |
46 ms |
8184 KB |
Output is correct |
12 |
Correct |
47 ms |
8168 KB |
Output is correct |
13 |
Correct |
46 ms |
8184 KB |
Output is correct |
14 |
Correct |
49 ms |
8148 KB |
Output is correct |
15 |
Correct |
47 ms |
8168 KB |
Output is correct |
16 |
Correct |
49 ms |
8156 KB |
Output is correct |
17 |
Correct |
47 ms |
8188 KB |
Output is correct |
18 |
Correct |
47 ms |
8200 KB |
Output is correct |
19 |
Correct |
47 ms |
8184 KB |
Output is correct |
20 |
Correct |
3 ms |
376 KB |
Output is correct |
21 |
Correct |
3 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
48 ms |
8216 KB |
Output is correct |
25 |
Correct |
47 ms |
8188 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
47 ms |
8212 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
29 |
Correct |
47 ms |
8184 KB |
Output is correct |
30 |
Correct |
47 ms |
8156 KB |
Output is correct |
31 |
Correct |
2 ms |
376 KB |
Output is correct |
32 |
Correct |
47 ms |
8156 KB |
Output is correct |
33 |
Correct |
47 ms |
8184 KB |
Output is correct |
34 |
Correct |
47 ms |
8176 KB |
Output is correct |
35 |
Correct |
47 ms |
8192 KB |
Output is correct |
36 |
Correct |
46 ms |
8180 KB |
Output is correct |
37 |
Correct |
47 ms |
8196 KB |
Output is correct |
38 |
Correct |
47 ms |
8184 KB |
Output is correct |
39 |
Correct |
47 ms |
8088 KB |
Output is correct |
40 |
Correct |
46 ms |
8184 KB |
Output is correct |
41 |
Correct |
47 ms |
8184 KB |
Output is correct |
42 |
Correct |
47 ms |
8160 KB |
Output is correct |
43 |
Correct |
46 ms |
8184 KB |
Output is correct |
44 |
Correct |
46 ms |
8156 KB |
Output is correct |
45 |
Correct |
47 ms |
8156 KB |
Output is correct |
46 |
Correct |
46 ms |
8184 KB |
Output is correct |
47 |
Correct |
46 ms |
8184 KB |
Output is correct |
48 |
Correct |
50 ms |
8184 KB |
Output is correct |
49 |
Correct |
46 ms |
8148 KB |
Output is correct |
50 |
Correct |
3 ms |
376 KB |
Output is correct |
51 |
Correct |
2 ms |
376 KB |
Output is correct |
52 |
Correct |
2 ms |
376 KB |
Output is correct |
53 |
Correct |
2 ms |
380 KB |
Output is correct |
54 |
Correct |
47 ms |
8244 KB |
Output is correct |
55 |
Correct |
46 ms |
8184 KB |
Output is correct |
56 |
Correct |
2 ms |
376 KB |
Output is correct |
57 |
Correct |
47 ms |
8312 KB |
Output is correct |
58 |
Correct |
2 ms |
376 KB |
Output is correct |
59 |
Correct |
46 ms |
8188 KB |
Output is correct |
60 |
Correct |
46 ms |
8184 KB |
Output is correct |
61 |
Correct |
2 ms |
376 KB |
Output is correct |
62 |
Correct |
47 ms |
8236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
8184 KB |
Output is correct |
2 |
Correct |
47 ms |
8188 KB |
Output is correct |
3 |
Correct |
49 ms |
8184 KB |
Output is correct |
4 |
Correct |
46 ms |
8184 KB |
Output is correct |
5 |
Correct |
46 ms |
8184 KB |
Output is correct |
6 |
Correct |
47 ms |
8184 KB |
Output is correct |
7 |
Correct |
47 ms |
8184 KB |
Output is correct |
8 |
Correct |
53 ms |
8184 KB |
Output is correct |
9 |
Correct |
50 ms |
8168 KB |
Output is correct |
10 |
Correct |
47 ms |
8184 KB |
Output is correct |
11 |
Correct |
46 ms |
8184 KB |
Output is correct |
12 |
Correct |
47 ms |
8168 KB |
Output is correct |
13 |
Correct |
46 ms |
8184 KB |
Output is correct |
14 |
Correct |
49 ms |
8148 KB |
Output is correct |
15 |
Correct |
47 ms |
8168 KB |
Output is correct |
16 |
Correct |
49 ms |
8156 KB |
Output is correct |
17 |
Correct |
47 ms |
8188 KB |
Output is correct |
18 |
Correct |
47 ms |
8200 KB |
Output is correct |
19 |
Correct |
47 ms |
8184 KB |
Output is correct |
20 |
Correct |
3 ms |
376 KB |
Output is correct |
21 |
Correct |
3 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
48 ms |
8216 KB |
Output is correct |
25 |
Correct |
47 ms |
8188 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
47 ms |
8212 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
29 |
Correct |
47 ms |
8184 KB |
Output is correct |
30 |
Correct |
47 ms |
8156 KB |
Output is correct |
31 |
Correct |
2 ms |
376 KB |
Output is correct |
32 |
Correct |
47 ms |
8156 KB |
Output is correct |
33 |
Correct |
47 ms |
8184 KB |
Output is correct |
34 |
Correct |
47 ms |
8176 KB |
Output is correct |
35 |
Correct |
47 ms |
8192 KB |
Output is correct |
36 |
Correct |
46 ms |
8180 KB |
Output is correct |
37 |
Correct |
47 ms |
8196 KB |
Output is correct |
38 |
Correct |
47 ms |
8184 KB |
Output is correct |
39 |
Correct |
47 ms |
8088 KB |
Output is correct |
40 |
Correct |
46 ms |
8184 KB |
Output is correct |
41 |
Correct |
47 ms |
8184 KB |
Output is correct |
42 |
Correct |
47 ms |
8160 KB |
Output is correct |
43 |
Correct |
46 ms |
8184 KB |
Output is correct |
44 |
Correct |
46 ms |
8156 KB |
Output is correct |
45 |
Correct |
47 ms |
8156 KB |
Output is correct |
46 |
Correct |
46 ms |
8184 KB |
Output is correct |
47 |
Correct |
46 ms |
8184 KB |
Output is correct |
48 |
Correct |
50 ms |
8184 KB |
Output is correct |
49 |
Correct |
46 ms |
8148 KB |
Output is correct |
50 |
Correct |
3 ms |
376 KB |
Output is correct |
51 |
Correct |
2 ms |
376 KB |
Output is correct |
52 |
Correct |
2 ms |
376 KB |
Output is correct |
53 |
Correct |
2 ms |
380 KB |
Output is correct |
54 |
Correct |
47 ms |
8244 KB |
Output is correct |
55 |
Correct |
46 ms |
8184 KB |
Output is correct |
56 |
Correct |
2 ms |
376 KB |
Output is correct |
57 |
Correct |
47 ms |
8312 KB |
Output is correct |
58 |
Correct |
2 ms |
376 KB |
Output is correct |
59 |
Correct |
46 ms |
8188 KB |
Output is correct |
60 |
Correct |
46 ms |
8184 KB |
Output is correct |
61 |
Correct |
2 ms |
376 KB |
Output is correct |
62 |
Correct |
47 ms |
8236 KB |
Output is correct |
63 |
Execution timed out |
1050 ms |
43440 KB |
Time limit exceeded |
64 |
Halted |
0 ms |
0 KB |
- |