답안 #131586

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
131586 2019-07-17T10:03:46 Z SirCeness Naan (JOI19_naan) C++14
29 / 100
40 ms 7928 KB
#include <bits/stdc++.h>

using namespace std;
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define bas(x) #x << ": " << x
#define prarr(x, n) cout << #x << ": "; for (int qsd = 0; qsd < n; qsd++) cout << x[qsd] << " "; cout << endl;
#define prarrv(x) cout << #x << ": "; for (int qsd = 0; qsd < (int)x.size(); qsd++) cout << x[qsd] << " "; cout << endl;
#define inside sl<=l%&&r<=sr
#define outside sr<l||r<sl

typedef long long ll;

int n, m;
int mat[2002][2002];
ll presum[2002][2002];

pair<double, double> sum(pair<double, double> a, pair<double, double> b){
	double pay = a.first*b.second + a.second*b.first;
	double payda = a.second*b.second;
	return mp(pay, payda);
}


pair<double, double> get(int i, double pay, double payda){
	/*double ans = presum[i][(int)(pay/payda)-1];
	ans += mat[i][(int)(pay/payda)]*((pay/payda) - (int)(pay/payda));
	return ans;*/
	return sum(mp(presum[i][(int)(pay/payda)-1], 1), mp((double)((int)pay%(int)payda)*mat[i][(int)(pay/payda)], payda));
}

pair<double, double> getmin(int i, pair<double, double> puan){
	//cout << "getmin(" << i << ", " << puan << ")" << endl;
	if (presum[i][m-1] < puan.first/puan.second) return mp(-1, -1);
	int l = 0;
	int r = m-1;
	while (l < r){
		int m = (l+r+1)/2;
		if (presum[i][m] > puan.first/puan.second) r = m-1;
		else l = m;
	}
	if (presum[i][l] == puan.first/puan.second) return mp(l+1, 1);
	puan = sum(puan, mp(-presum[i][l], 1));
	// mat[i][l+1]*oran = puan;
	return sum(mp(l+1, 1), mp(puan.first, puan.second*mat[i][l+1]));
}

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	cin >> n >> m;
	for (int i = 0; i < n; i++){
		ll cur = 0;
		for (int j = 0; j < m; j++){
			cin >> mat[i][j];
			cur += mat[i][j];
			presum[i][j] = cur;
		}
	}
	
	/*for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			cout << mat[i][j] << " ";
		}
		cout << endl;
	}
	cout << endl;
	
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			cout << presum[i][j] << " ";
		}
		cout << endl;
	}
	cout << endl;*/
	
	vector<pair<ll, ll> > ans;
	vector<int> p;
	bitset<2002> vis;
	vis.reset();
	
	double cpay = 0;
	double cpayda = 1;
	for (int bol = 0; bol < n; bol++){
		//cout << bas(bol) << endl;
		double minpay = 10000000;
		double minpayda = 1;
		int ci = 0;
		for (int i = 0; i < n; i++){
			if (vis[i]) continue;
			//cout << bas(i) << endl;
			pair<double, double> suan = get(i, cpay, cpayda);
			pair<double, double> minoran = getmin(i, sum(suan, mp(presum[i][m-1], (double)n)));
			//cout << bas(minoran.first) << ", " << bas(minoran.second) << endl;
			if (minoran.first == -1){
				cout << -1 << endl;
				exit(0);
			}
			if (minpay/minpayda > minoran.first/minoran.second){
				minpay = minoran.first;
				minpayda = minoran.second;
				ci = i;
			}
		}
		cpay = minpay;
		cpayda = minpayda; 
		
		ans.pb(mp(cpay, cpayda));
		p.pb(ci+1);
		vis[ci] = 1;
		//cout << cpay << " " << cpayda << " -> " << ci << endl;
	}
	
	for (int i = 0; i < n-1; i++) cout << ans[i].first << " " << ans[i].second << endl;
	for (int i = 0; i < n; i++) cout << p[i] << " ";
	cout << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 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 2 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 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 2 ms 504 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 3 ms 552 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 504 KB Output is correct
16 Correct 3 ms 504 KB Output is correct
17 Correct 3 ms 508 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 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 380 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 2 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 3 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 2 ms 504 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 2 ms 380 KB Output is correct
23 Correct 3 ms 504 KB Output is correct
24 Correct 3 ms 504 KB Output is correct
25 Correct 3 ms 504 KB Output is correct
26 Correct 3 ms 552 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 504 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 3 ms 508 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 3 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 40 ms 7928 KB Integer parameter [name=A_i] equals to -1, violates the range [1, 2000000000000]
44 Halted 0 ms 0 KB -