# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
123886 |
2019-07-02T08:35:12 Z |
이온조(#3029) |
Naan (JOI19_naan) |
C++14 |
|
52 ms |
6804 KB |
#include <bits/stdc++.h>
using namespace std;
using pll = pair<__int128, __int128>;
#define X first
#define Y second
const pll INF = {(__int128)1e18 * (__int128)1e18, 1};
__int128 A[2009], V[2009][2009];
int N, L;
bool operator <(pll P, pll Q) {
if(P == INF) return 0;
if(Q == INF) return 1;
return P.X * Q.Y < Q.X * P.Y;
}
pll f(__int128 a, __int128 b) {
__int128 gcd = __gcd(a, b);
a /= gcd; b /= gcd;
// while(b >= 1000000000LL) {
// if(a & 1) ++a;
// if(b & 1) --b;
// a >>= 1LL; b >>= 1LL;
// }
return {a, b};
}
pll R(int i, pll st) {
if(st > INF || st == INF) return INF;
__int128 div = st.X / st.Y, mod = st.X % st.Y, lft = st.Y - mod;
__int128 a, b;
// lft / st.Y * V[i][div] >= A[i] / N
if(lft * V[i][div] * N >= 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 = st.X * V[i][div] * N + A[i] * st.Y;
b = V[i][div] * N * st.Y;
return f(a, b);
}
else {
__int128 sa, sb;
sa = 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(sa * N + V[i][j] * sb * N >= 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 = V[i][j] * sb * N;
a = b * j + A[i] * sb - sa * N;
return f(a, b);
}
sa += sb * V[i][j];
tie(sa, sb) = f(sa, sb);
}
}
return INF;
}
int main() {
scanf("%d%d",&N,&L);
for(int i=1; i<=N; i++) {
for(int j=0; j<L; j++) {
int foo;
scanf("%d",&foo);
V[i][j] = foo;
A[i] += V[i][j];
}
}
vector<int> S, P;
vector<pll> ans; pll now = {0, 1};
for(int i=1; i<=N; i++) S.push_back(i);
for(int i=1; i<=N; i++) {
int mni = -1; pll mn = INF;
for(int j=0; j<S.size(); j++) {
pll tmp = R(S[j], now);
if(tmp < mn) mn = tmp, mni = j;
}
now = mn;
ans.push_back(now);
P.push_back(S[mni]);
if(mni == -1) return !printf("-1");
S.erase(S.begin() + mni);
}
if(now < (pll){L, 1LL} || now == (pll){L, 1LL}) {
for(int i=0; i<N-1; i++) printf("%lld %lld\n", (long long)ans[i].X, (long long)ans[i].Y);
for(auto& it: P) printf("%d ", it);
}
else puts("-1");
return 0;
}
Compilation message
naan.cpp: In function 'int main()':
naan.cpp:79:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0; j<S.size(); j++) {
~^~~~~~~~~
naan.cpp:65: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:69:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&foo);
~~~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
2 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 |
3 ms |
376 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
508 KB |
Output is correct |
4 |
Correct |
4 ms |
504 KB |
Output is correct |
5 |
Correct |
3 ms |
508 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
4 ms |
504 KB |
Output is correct |
10 |
Correct |
3 ms |
504 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
504 KB |
Output is correct |
15 |
Correct |
3 ms |
504 KB |
Output is correct |
16 |
Correct |
3 ms |
504 KB |
Output is correct |
17 |
Correct |
3 ms |
504 KB |
Output is correct |
18 |
Correct |
4 ms |
504 KB |
Output is correct |
19 |
Correct |
3 ms |
504 KB |
Output is correct |
20 |
Correct |
3 ms |
504 KB |
Output is correct |
21 |
Correct |
4 ms |
504 KB |
Output is correct |
22 |
Correct |
4 ms |
504 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
3 ms |
504 KB |
Output is correct |
25 |
Correct |
3 ms |
504 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
3 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
2 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 |
3 ms |
376 KB |
Output is correct |
13 |
Correct |
3 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 |
376 KB |
Output is correct |
18 |
Correct |
3 ms |
508 KB |
Output is correct |
19 |
Correct |
4 ms |
504 KB |
Output is correct |
20 |
Correct |
3 ms |
508 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 |
4 ms |
504 KB |
Output is correct |
25 |
Correct |
3 ms |
504 KB |
Output is correct |
26 |
Correct |
3 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
3 ms |
376 KB |
Output is correct |
29 |
Correct |
3 ms |
504 KB |
Output is correct |
30 |
Correct |
3 ms |
504 KB |
Output is correct |
31 |
Correct |
3 ms |
504 KB |
Output is correct |
32 |
Correct |
3 ms |
504 KB |
Output is correct |
33 |
Correct |
4 ms |
504 KB |
Output is correct |
34 |
Correct |
3 ms |
504 KB |
Output is correct |
35 |
Correct |
3 ms |
504 KB |
Output is correct |
36 |
Correct |
4 ms |
504 KB |
Output is correct |
37 |
Correct |
4 ms |
504 KB |
Output is correct |
38 |
Correct |
2 ms |
376 KB |
Output is correct |
39 |
Correct |
3 ms |
504 KB |
Output is correct |
40 |
Correct |
3 ms |
504 KB |
Output is correct |
41 |
Correct |
2 ms |
376 KB |
Output is correct |
42 |
Correct |
3 ms |
504 KB |
Output is correct |
43 |
Incorrect |
52 ms |
6804 KB |
Integer parameter [name=A_i] equals to -1, violates the range [1, 2000000000000] |
44 |
Halted |
0 ms |
0 KB |
- |