Submission #7035658
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
void read(pp& x){ scanf("%d%d",&x.first, &x.second); }
void read(pll& x){ scanf("%lld%lld",&x.first, &x.second); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
void cppio(){ ios_base::sync_with_stdio(0); cin.tie(0); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define sz(x) (int)(x).size()
const int maxn = int(2e5) + 10;
int n;
int a[maxn];
int b[maxn];
int main()
{
cppio();
cin >> n;
rrep(i, n) cin >> a[i];
rrep(i, n) cin >> b[i];
priority_queue<pp> pq;
rrep(i, n) pq.emplace(b[i], i);
ll cnt = 0;
while(pq.size()) {
int x, i; tie(x, i) = pq.top(); pq.pop();
//printf("pop i %d x %d (b %d)\n", i, x, b[i]);
if(b[i] != x) continue;
if(b[i] < a[i]) {
cout << -1 << '\n';
return 0;
}
if(b[i] == a[i]) continue;
int i1 = (i+n-2)%n + 1;
int i2 = i%n + 1;
int df = (b[i1] + b[i2]);
int c = (b[i] - max({a[i], b[i1] + b[i2]}) + df - 1) / df;
if(c == 0) continue;
//printf("b: %d (%d) %d / df %d, c %d\n", b[i1], b[i], b[i2], df, c);
cnt += c;
b[i] -= df * c;
pq.emplace(b[i], i);
}
rrep(i, n) if(a[i] != b[i]) {
cout << -1 << '\n';
return 0;
}
cout << cnt << endl;
return 0;
}
Submission Info
| Submission Time |
|
| Task |
C - Numbers on a Circle |
| User |
Namnamseo |
| Language |
C++14 (GCC 5.4.1) |
| Score |
800 |
| Code Size |
1621 Byte |
| Status |
AC |
| Exec Time |
261 ms |
| Memory |
3956 KiB |
Compile Error
./Main.cpp: In function ‘void read(int&)’:
./Main.cpp:6:34: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
void read(int& x){ scanf("%d",&x); }
^
./Main.cpp: In function ‘void read(ll&)’:
./Main.cpp:7:35: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
void read(ll& x){ scanf("%lld",&x); }
^
./Main.cpp: In function ‘void read(pp&)’:
./Main.cpp:8:52: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
void read(pp& x){ scanf("%d%d",&x.first, &x.second); }
^
./Main.cpp: In function ‘void read(pll&)’:
./Main.cpp:9:57: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
void read(pll& x){...
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
800 / 800 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
sample01.txt, sample02.txt, sample03.txt |
| All |
sample01.txt, sample02.txt, sample03.txt, in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, in29.txt, in30.txt, in31.txt, in32.txt, in33.txt, in34.txt, sample01.txt, sample02.txt, sample03.txt |
| Case Name |
Status |
Exec Time |
Memory |
| in01.txt |
AC |
77 ms |
3828 KiB |
| in02.txt |
AC |
80 ms |
3828 KiB |
| in03.txt |
AC |
73 ms |
3828 KiB |
| in04.txt |
AC |
72 ms |
3828 KiB |
| in05.txt |
AC |
68 ms |
3700 KiB |
| in06.txt |
AC |
73 ms |
3828 KiB |
| in07.txt |
AC |
80 ms |
3828 KiB |
| in08.txt |
AC |
83 ms |
3828 KiB |
| in09.txt |
AC |
260 ms |
3956 KiB |
| in10.txt |
AC |
260 ms |
3956 KiB |
| in11.txt |
AC |
261 ms |
3956 KiB |
| in12.txt |
AC |
222 ms |
3956 KiB |
| in13.txt |
AC |
175 ms |
3956 KiB |
| in14.txt |
AC |
173 ms |
3956 KiB |
| in15.txt |
AC |
133 ms |
3956 KiB |
| in16.txt |
AC |
133 ms |
3956 KiB |
| in17.txt |
AC |
117 ms |
3956 KiB |
| in18.txt |
AC |
117 ms |
3956 KiB |
| in19.txt |
AC |
79 ms |
3956 KiB |
| in20.txt |
AC |
82 ms |
3956 KiB |
| in21.txt |
AC |
40 ms |
3828 KiB |
| in22.txt |
AC |
48 ms |
3828 KiB |
| in23.txt |
AC |
2 ms |
256 KiB |
| in24.txt |
AC |
1 ms |
256 KiB |
| in25.txt |
AC |
2 ms |
256 KiB |
| in26.txt |
AC |
2 ms |
256 KiB |
| in27.txt |
AC |
2 ms |
256 KiB |
| in28.txt |
AC |
2 ms |
256 KiB |
| in29.txt |
AC |
2 ms |
256 KiB |
| in30.txt |
AC |
2 ms |
256 KiB |
| in31.txt |
AC |
2 ms |
384 KiB |
| in32.txt |
AC |
2 ms |
256 KiB |
| in33.txt |
AC |
3 ms |
256 KiB |
| in34.txt |
AC |
2 ms |
256 KiB |
| sample01.txt |
AC |
1 ms |
256 KiB |
| sample02.txt |
AC |
1 ms |
256 KiB |
| sample03.txt |
AC |
1 ms |
256 KiB |