# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
123799 |
2019-07-02T07:02:01 Z |
이온조(#3029) |
Naan (JOI19_naan) |
C++14 |
|
46 ms |
7032 KB |
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
#define X first
#define Y second
int N, L, V[2009][2009], A[2009];
pii f(long long a, long long b) {
long long gcd = __gcd(a, b);
return {a / gcd, b / gcd};
}
pii R(int i, pii st) {
int div = st.X / st.Y, mod = st.X % st.Y, lft = st.Y - mod;
long long a, b;
// lft / st.Y * V[i][div] >= A[i] / N
if(1LL * lft * V[i][div] * N >= 1LL * A[i] * st.Y) {
// ((a / b) - (st.X / st.Y)) * V[i][div] == A[i] / N
// ((a / b) - (st.X / st.Y)) * V[i][div] * N == A[i]
// (a / b) * V[i][div] * N - (st.X / st.Y) * V[i][div] * N == A[i]
// (a / b) * V[i][div] * N * st.Y - st.X * V[i][div] * N == A[i] * st.Y
// (a / b) * V[i][div] * N * st.Y = st.X * V[i][div] * N + A[i] * st.Y
a = 1LL * st.X * V[i][div] * N + 1LL * A[i] * st.Y;
b = 1LL * V[i][div] * N * st.Y;
return f(a, b);
}
else {
long long sa, sb;
sa = 1LL * lft * V[i][div]; sb = st.Y;
tie(sa, sb) = f(sa, sb);
for(int j=div+1; j<L; j++) {
// sa / sb + V[i][j] >= A[i] / N
if(1LL * sa * N + 1LL * V[i][j] * sb * N >= 1LL * A[i] * sb) {
// (a / b) * V[i][j] + (sa / sb) == A[i] / N
// a/b * V[i][j] * sb * N + sa * N == A[i] * sb
// a/b * V[i][j] * sb * N == A[i] * sb - sa * N;
b = 1LL * V[i][j] * sb * N;
a = 1LL * b * j + 1LL * A[i] * sb - 1LL * sa * N;
return f(a, b);
}
sa += 1LL * sb * V[i][j];
tie(sa, sb) = f(sa, sb);
}
}
return {1e9, 1};
}
int main() {
scanf("%d%d",&N,&L);
for(int i=1; i<=N; i++) {
for(int j=0; j<L; j++) {
scanf("%d",&V[i][j]);
A[i] += V[i][j];
}
}
vector<int> S;
for(int i=1; i<=N; i++) S.push_back(i);
do {
// puts("S");
// for(auto& it: S) printf("%d ", it);
// puts("\n----------------------\nposition");
vector<pii> ans;
pii now = {0, 1};
for(auto& it: S) {
// printf("%d %d\n", now.first, now.second);
now = R(it, now);
ans.push_back(now);
}
// puts("----------------------");
if(1LL * now.X <= 1LL * L * now.Y) {
for(int i=0; i<N-1; i++) printf("%d %d\n", ans[i].X, ans[i].Y);
for(auto& it: S) printf("%d ",it);
return 0;
}
} while(next_permutation(S.begin(), S.end()));
puts("-1");
return 0;
}
Compilation message
naan.cpp: In function 'int main()':
naan.cpp:50:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&N,&L);
~~~~~^~~~~~~~~~~~~~
naan.cpp:53:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&V[i][j]);
~~~~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
372 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
368 KB |
Output is correct |
5 |
Correct |
2 ms |
296 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
372 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
372 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
396 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
404 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
17 |
Correct |
3 ms |
412 KB |
Output is correct |
18 |
Correct |
3 ms |
376 KB |
Output is correct |
19 |
Correct |
3 ms |
408 KB |
Output is correct |
20 |
Correct |
3 ms |
396 KB |
Output is correct |
21 |
Correct |
3 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
3 ms |
376 KB |
Output is correct |
25 |
Correct |
3 ms |
400 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
372 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
368 KB |
Output is correct |
5 |
Correct |
2 ms |
296 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
372 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
372 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
380 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
3 ms |
348 KB |
Output is correct |
19 |
Correct |
3 ms |
396 KB |
Output is correct |
20 |
Correct |
3 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
404 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
3 ms |
376 KB |
Output is correct |
26 |
Correct |
3 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
376 KB |
Output is correct |
29 |
Correct |
3 ms |
376 KB |
Output is correct |
30 |
Correct |
3 ms |
376 KB |
Output is correct |
31 |
Correct |
3 ms |
376 KB |
Output is correct |
32 |
Correct |
3 ms |
412 KB |
Output is correct |
33 |
Correct |
3 ms |
376 KB |
Output is correct |
34 |
Correct |
3 ms |
408 KB |
Output is correct |
35 |
Correct |
3 ms |
396 KB |
Output is correct |
36 |
Correct |
3 ms |
376 KB |
Output is correct |
37 |
Correct |
3 ms |
340 KB |
Output is correct |
38 |
Correct |
2 ms |
376 KB |
Output is correct |
39 |
Correct |
3 ms |
376 KB |
Output is correct |
40 |
Correct |
3 ms |
400 KB |
Output is correct |
41 |
Correct |
2 ms |
376 KB |
Output is correct |
42 |
Correct |
3 ms |
376 KB |
Output is correct |
43 |
Runtime error |
46 ms |
7032 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
44 |
Halted |
0 ms |
0 KB |
- |