답안 #1006388

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1006388 2024-06-24T00:14:12 Z AdamGS Naan (JOI19_naan) C++17
100 / 100
210 ms 53964 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const ll INF=1e9+7;
const int LIM=2e3+7;
ll T[LIM][LIM], sum[LIM], odw[LIM], n, l;
bool mniejszy(pair<pair<ll,ll>,ll>a, pair<pair<ll,ll>,ll>b) {
	ll x=a.st.st*b.st.nd, y=b.st.st*a.st.nd;
	if(x==y) return a.nd<b.nd;
	return x<y;
}
pair<pair<ll,ll>,ll>nxt(pair<ll,ll>x) {
	pair<pair<ll,ll>,ll>ans={{INF, 1}, INF};
	rep(i, n) if(!odw[i]) {
		ll p=x.st/x.nd, q=x.st-p*x.nd;
		ll a=(T[i][p]*q+x.nd-1)/x.nd;
		ll c=T[i][p]-a;
		if(c>=sum[i]) {
			a+=sum[i];
			pair<pair<ll,ll>,ll>t={{a+p*T[i][p], T[i][p]}, i};
			if(mniejszy(t, ans)) ans=t;
			continue;
		}
		ll d=p+1;
		while(c+T[i][d]<sum[i]) {
			c+=T[i][d];
			++d;
		}
		ll e=sum[i]-c;
		pair<pair<ll,ll>,ll>t={{e+d*T[i][d], T[i][d]}, i};
		if(mniejszy(t, ans)) ans=t;
	}
	return ans;
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n >> l;
	rep(i, n) {
		rep(j, l) {
			cin >> T[i][j];
			sum[i]+=T[i][j];
			T[i][j]*=n;
		}
	}
	vector<ll>P;
	pair<ll,ll>akt={0, 1};
	rep(i, n-1) {
		pair<pair<ll,ll>,ll>x=nxt(akt);
		P.pb(x.nd);
		odw[x.nd]=1;
		akt=x.st;
		cout << akt.st << " " << akt.nd << '\n';
	}
	rep(i, n) if(!odw[i]) P.pb(i);
	for(auto i : P) cout << i+1 << " ";
	cout << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 476 KB Output is correct
15 Correct 0 ms 432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 476 KB Output is correct
15 Correct 0 ms 432 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 16 ms 12124 KB Output is correct
44 Correct 95 ms 33104 KB Output is correct
45 Correct 82 ms 20308 KB Output is correct
46 Correct 11 ms 3676 KB Output is correct
47 Correct 78 ms 25052 KB Output is correct
48 Correct 76 ms 33108 KB Output is correct
49 Correct 24 ms 16040 KB Output is correct
50 Correct 116 ms 36944 KB Output is correct
51 Correct 66 ms 20596 KB Output is correct
52 Correct 132 ms 36180 KB Output is correct
53 Correct 91 ms 32084 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 16 ms 23388 KB Output is correct
56 Correct 67 ms 25320 KB Output is correct
57 Correct 64 ms 24400 KB Output is correct
58 Correct 78 ms 31060 KB Output is correct
59 Correct 80 ms 23272 KB Output is correct
60 Correct 185 ms 53840 KB Output is correct
61 Correct 209 ms 53844 KB Output is correct
62 Correct 193 ms 53720 KB Output is correct
63 Correct 197 ms 53964 KB Output is correct
64 Correct 210 ms 53852 KB Output is correct
65 Correct 142 ms 40528 KB Output is correct
66 Correct 155 ms 40412 KB Output is correct
67 Correct 153 ms 40532 KB Output is correct
68 Correct 93 ms 29032 KB Output is correct
69 Correct 86 ms 28756 KB Output is correct
70 Correct 80 ms 31608 KB Output is correct
71 Correct 125 ms 38228 KB Output is correct