Submission #131827

# Submission time Handle Problem Language Result Execution time Memory
131827 2019-07-17T17:49:22 Z SirCeness Naan (JOI19_naan) C++14
100 / 100
919 ms 125896 KB
#include <bits/stdc++.h>
 
using namespace std;
#define mod 998244353
#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;
ll mat[2002][2002];
ll presum[2002][2002];
pair<ll, ll> bol[2002][2002];

vector<pair<ll, ll> > ans;
vector<int> p;
 
pair<ll, ll> sum(pair<ll, ll> a, pair<ll, ll> b){
	ll pay = a.first*b.second + a.second*b.first;
	ll payda = a.second*b.second;
	return mp(pay, payda);
}
 
 
pair<ll, ll> get(int i, ll pay, ll payda){
	cout << "get(" << i << ", " << pay << ", "  << payda << ")" << endl;
	/*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][(pay/payda)-1], 1), mp((pay%payda)*mat[i][pay/payda], payda));
}

pair<ll, ll> getmin(int i, pair<ll, ll> puan){
	//cout << "getmin(" << i << ", " << puan.first << ", " << puan.second << ")" << endl;
	if (presum[i][m-1] < (double)puan.first/(double)puan.second) return mp(-1, -1);
	int l = -1;
	int r = m-1;
	while (l < r){
		int m = (l+r+1)/2;
		if (presum[i][m] > (double)puan.first/(double)puan.second) r = m-1;
		else l = m;
	}
	//cout << bas(l) << endl;
	if (l != -1 && presum[i][l] == (double)puan.first/(double)puan.second) return mp(l+1, 1);
	puan = sum(puan, mp((l == -1) ? 0 : -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 < n; j++){
			bol[j][i] = getmin(i, mp(presum[i][m-1]*(j+1), n)); 
			//cout << bol[i][j].first << ", " << bol[i][j].second  << " ";
		}
		//cout << endl;
	}
	//cout << endl;
	
	bitset<2002> vis;
	vis.reset();
	for (int i = 0; i < n; i++){
		double minn = 1000000000;
		int mini = -1;
		for (int j = 0; j < n; j++){
			if (vis[j]) continue;
			//cout << bas(i) << " " bas(j) << endl;
			//cout << bas(minn) << " " << bas(bol[i][j].first) << bas(bol[i][j].second) << endl;
 			if ((double)bol[i][j].first / (double)bol[i][j].second < minn){
				minn = (double)bol[i][j].first / (double)bol[i][j].second;
				mini = j;
			}
		}
		ans.pb(bol[i][mini]);
		p.pb(mini+1);
		vis[mini] = 1;
	}
	
	for (int i = 0; i < n-1; i++) cout << ans[i].first << " " << ans[i].second << endl;
	
	for (int i = 0; i < p.size(); i++) cout << p[i] << " ";
	
}

Compilation message

naan.cpp: In function 'int main()':
naan.cpp:97:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < p.size(); i++) cout << p[i] << " ";
                  ~~^~~~~~~~~~
# Verdict Execution time Memory 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 3 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 3 ms 632 KB Output is correct
5 Correct 3 ms 476 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 3 ms 632 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 3 ms 504 KB Output is correct
16 Correct 3 ms 632 KB Output is correct
17 Correct 3 ms 632 KB Output is correct
18 Correct 3 ms 632 KB Output is correct
19 Correct 3 ms 632 KB Output is correct
20 Correct 3 ms 504 KB Output is correct
21 Correct 3 ms 632 KB Output is correct
22 Correct 3 ms 632 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 580 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 3 ms 504 KB Output is correct
# Verdict Execution time Memory 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 3 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 504 KB Output is correct
18 Correct 2 ms 504 KB Output is correct
19 Correct 3 ms 632 KB Output is correct
20 Correct 3 ms 476 KB Output is correct
21 Correct 2 ms 504 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 2 ms 504 KB Output is correct
24 Correct 3 ms 504 KB Output is correct
25 Correct 3 ms 632 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 3 ms 504 KB Output is correct
31 Correct 3 ms 632 KB Output is correct
32 Correct 3 ms 632 KB Output is correct
33 Correct 3 ms 632 KB Output is correct
34 Correct 3 ms 632 KB Output is correct
35 Correct 3 ms 504 KB Output is correct
36 Correct 3 ms 632 KB Output is correct
37 Correct 3 ms 632 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 580 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 3 ms 504 KB Output is correct
43 Correct 70 ms 16248 KB Output is correct
44 Correct 417 ms 73076 KB Output is correct
45 Correct 214 ms 32248 KB Output is correct
46 Correct 28 ms 4856 KB Output is correct
47 Correct 285 ms 49516 KB Output is correct
48 Correct 310 ms 87672 KB Output is correct
49 Correct 97 ms 30456 KB Output is correct
50 Correct 488 ms 118056 KB Output is correct
51 Correct 235 ms 54264 KB Output is correct
52 Correct 515 ms 106872 KB Output is correct
53 Correct 399 ms 100568 KB Output is correct
54 Correct 3 ms 504 KB Output is correct
55 Correct 130 ms 50516 KB Output is correct
56 Correct 305 ms 72440 KB Output is correct
57 Correct 246 ms 63992 KB Output is correct
58 Correct 372 ms 97164 KB Output is correct
59 Correct 267 ms 59512 KB Output is correct
60 Correct 887 ms 125856 KB Output is correct
61 Correct 919 ms 125896 KB Output is correct
62 Correct 888 ms 125432 KB Output is correct
63 Correct 891 ms 125720 KB Output is correct
64 Correct 906 ms 125752 KB Output is correct
65 Correct 599 ms 125716 KB Output is correct
66 Correct 616 ms 125864 KB Output is correct
67 Correct 659 ms 125892 KB Output is correct
68 Correct 363 ms 72672 KB Output is correct
69 Correct 404 ms 68344 KB Output is correct
70 Correct 428 ms 85984 KB Output is correct
71 Correct 574 ms 96248 KB Output is correct