답안 #123701

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
123701 2019-07-02T04:52:16 Z 윤교준(#3030) Naan (JOI19_naan) C++14
29 / 100
4000 ms 7928 KB
#include <bits/stdc++.h>
#define eb emplace_back
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { for(;b;a%=b,swap(a,b)){} return a; }

struct FRC {
	FRC(ll a, ll b) : a(a), b(b) { norm(); }
	FRC(ll a) : a(a), b(1) {}
	FRC() : a(0), b(1) {}
	ll a, b; // a / b

	void prt() const { printf("%lld %lld\n", a, b); }
	void norm() {
		if(!a) {
			b = 1;
			return;
		}
		if(b < 0) {
			a = -a;
			b = -b;
		}
		ll g = gcd(abs(a), b);
		if(g) {
			a /= g;
			b /= g;
		}
	}

	FRC operator + (const FRC &A) const {
		return FRC(a*A.b + b*A.a, b*A.b);
	}
	FRC operator - (const FRC &A) const {
		return FRC(a*A.b - b*A.a, b*A.b);
	}
	FRC operator * (const FRC &A) const {
		return FRC(a*A.a, b*A.b);
	}
	FRC operator / (const FRC &A) const {
		return FRC(a*A.b, b*A.a);
	}

	bool operator == (const FRC &A) const {
		return a == A.a && b == A.b;
	}
	bool operator < (const FRC &A) const {
		return a*A.b < b*A.a;
	}
	bool operator <= (const FRC &A) const {
		return a*A.b <= b*A.a;
	}
};


const int MAXN = 2005;
const int MAXK = 2005;

ll AS[MAXN][MAXK];
int A[MAXN][MAXK];

FRC pos[MAXN];
int O[MAXN];

int N, K;

bool solve() {
	for(int oi = 1, i, j = 1; oi <= N; oi++) {
		i = O[oi];
		FRC nd(AS[i][K], N), sum, pv = pos[oi-1];
		for(; j <= K; j++) {
			FRC more = (FRC(j) - pv) * A[i][j];
			if(nd <= sum + more) break;
			sum = sum + more;
			pv = j;
		}
		if(K < j) return false;
		pos[oi] = pv + (nd - sum) / A[i][j];
	}
	return true;
}

int main() {
	ios::sync_with_stdio(false);

	cin >> N >> K;
	for(int i = 1; i <= N; i++) {
		for(int j = 1; j <= K; j++) {
			cin >> A[i][j];
			AS[i][j] = AS[i][j-1] + A[i][j];
		}
	}

	iota(O, O+N+1, 0);
	do {
		if(!solve()) continue;
		for(int i = 1; i < N; i++) pos[i].prt();
		for(int i = 1; i <= N; i++) printf("%d ", O[i]);
		puts("");
		exit(0);
	} while(next_permutation(O+1, O+N+1));

	exit(-1);
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 3 ms 472 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 3 ms 504 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 504 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 3 ms 504 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
15 Correct 3 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 9 ms 504 KB Output is correct
10 Correct 3 ms 508 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 504 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
15 Correct 4 ms 504 KB Output is correct
16 Correct 3 ms 504 KB Output is correct
17 Correct 4 ms 504 KB Output is correct
18 Correct 3 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 3 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 504 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 504 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 3 ms 472 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 3 ms 504 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 504 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 3 ms 504 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
15 Correct 3 ms 380 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 504 KB Output is correct
18 Correct 3 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 3 ms 504 KB Output is correct
22 Correct 3 ms 504 KB Output is correct
23 Correct 2 ms 504 KB Output is correct
24 Correct 9 ms 504 KB Output is correct
25 Correct 3 ms 508 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 504 KB Output is correct
29 Correct 3 ms 504 KB Output is correct
30 Correct 4 ms 504 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 4 ms 504 KB Output is correct
33 Correct 3 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 3 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 504 KB Output is correct
42 Correct 3 ms 504 KB Output is correct
43 Execution timed out 4083 ms 7928 KB Time limit exceeded
44 Halted 0 ms 0 KB -