# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
290614 | 2020-09-04T07:38:37 Z | PeppaPig | Naan (JOI19_naan) | C++14 | 2 ms | 544 KB |
#include <bits/stdc++.h> #define long long long using namespace std; const int N = 2e3 + 5; struct Fraction { long x, y; Fraction() {} Fraction(long x, long y) : x(x), y(y) {} friend bool operator<(const Fraction &a, const Fraction &b) { if(a.x / a.y != b.x / b.y) return a.x / a.y < b.x / b.y; return (a.x % a.y) * b.y < (b.x % b.y) * a.y; } } pos[N][N]; int n, m; int ans[N], chk[N]; long v[N][N]; Fraction get_pos(int idx, long x, long y) { int l = 1, r = m; while(l < r) { int mid = (l + r) >> 1; if(v[idx][mid] * y > x) r = mid; else l = mid + 1; } x -= v[idx][r - 1] * y; y *= (v[idx][r] - v[idx][r - 1]); x += (r - 1) * y; return Fraction(x, y); } int main() { scanf("%d %d", &n, &m); for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { scanf("%lld", v[i] + j); v[i][j] += v[i][j - 1]; } for(int j = 1; j <= n; j++) pos[i][j] = get_pos(i, 1ll * j * v[i][m], n); } for(int i = 1; i <= n; i++) { int nex = -1; for(int j = 1; j <= n; j++) if(!chk[j] && (nex == -1 || pos[j][i] < pos[nex][i])) nex = i; ans[i] = nex, chk[nex] = 1; if(i < n) printf("%lld %lld\n", pos[nex][i].x, pos[nex][i].y); } for(int i = 1; i <= n; i++) printf("%d ", ans[i]); printf("\n"); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 384 KB | Not a fair distribution. |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 512 KB | Output is correct |
5 | Correct | 1 ms | 512 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 384 KB | Output is correct |
8 | Correct | 1 ms | 384 KB | Output is correct |
9 | Correct | 2 ms | 512 KB | Output is correct |
10 | Correct | 1 ms | 512 KB | Output is correct |
11 | Correct | 1 ms | 384 KB | Output is correct |
12 | Correct | 1 ms | 384 KB | Output is correct |
13 | Correct | 1 ms | 512 KB | Output is correct |
14 | Correct | 2 ms | 512 KB | Output is correct |
15 | Correct | 2 ms | 544 KB | Output is correct |
16 | Correct | 2 ms | 512 KB | Output is correct |
17 | Correct | 1 ms | 512 KB | Output is correct |
18 | Correct | 2 ms | 512 KB | Output is correct |
19 | Correct | 2 ms | 512 KB | Output is correct |
20 | Correct | 2 ms | 512 KB | Output is correct |
21 | Correct | 2 ms | 512 KB | Output is correct |
22 | Correct | 2 ms | 512 KB | Output is correct |
23 | Incorrect | 0 ms | 384 KB | Not a fair distribution. |
24 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 384 KB | Not a fair distribution. |
2 | Halted | 0 ms | 0 KB | - |