답안 #124001

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
124001 2019-07-02T10:40:15 Z onjo0127 Naan (JOI19_naan) C++11
29 / 100
902 ms 47824 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define X first
#define Y second
 
const pll INF = {1e9, 1};
int N, L, V[2009][2009], A[2009];
pll D[2009][2009];
 
bool operator <(pll P, pll Q) {
	return 1LL * P.X * Q.Y < 1LL * Q.X * P.Y;
}

pll f(ll a, ll b) {
	ll gcd = __gcd(a, b);
	return {a / gcd, b / gcd};
}
 
void R(int i) {
	ll a, b, s = 0;
	int k = 1;
	for(int j=0; j<L; j++) {
		// s + V[i][j] >= A[i] / N * k
		if(1LL * (s + V[i][j]) * N >= 1LL * A[i] * k) {
			// (a / b) * V[i][j] + s == A[i] / N * k
			// a/b * V[i][j] * N == A[i] * k - s * N
			b = 1LL * V[i][j] * N;
			a = 1LL * j * b + 1LL * A[i] * k - s * N;
			D[i][k] = f(a, b);
			++k; --j;
			continue;
		}
		s += V[i][j];
	}
	while(k <= N) D[i][k++] = {L, 1};
}

bool chk[2009];

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];
		}
		R(i);
	}
	vector<pll> pos; vector<int> P;
	for(int i=1; i<=N; i++) {
		pll mn = INF; int mni = -1;
		for(int j=1; j<=N; j++) if(!chk[j]) {
			if(D[j][i] < mn) {
				mn = D[j][i];
				mni = j;
			}
		}
		pos.push_back(mn);
		P.push_back(mni);
		chk[mni] = 1;
	}
	for(int i=0; i<N-1; i++) printf("%lld %lld\n", pos[i].X, pos[i].Y);
	for(auto& it: P) printf("%d ", it);
	return 0;
}

Compilation message

naan.cpp: In function 'int main()':
naan.cpp:43: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:46: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 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 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 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 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 376 KB Output is correct
15 Correct 3 ms 376 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 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 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 3 ms 504 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 504 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 504 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 3 ms 504 KB Output is correct
22 Correct 3 ms 376 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 376 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 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 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 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 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 376 KB Output is correct
15 Correct 3 ms 376 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 376 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 2 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 3 ms 504 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 3 ms 504 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 504 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 376 KB Output is correct
33 Correct 3 ms 504 KB Output is correct
34 Correct 3 ms 376 KB Output is correct
35 Correct 3 ms 376 KB Output is correct
36 Correct 3 ms 504 KB Output is correct
37 Correct 3 ms 376 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 376 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 3 ms 376 KB Output is correct
43 Correct 151 ms 11484 KB Output is correct
44 Incorrect 902 ms 47824 KB X_i is not increasing
45 Halted 0 ms 0 KB -