Submission #209369

# Submission time Handle Problem Language Result Execution time Memory
209369 2020-03-14T02:51:15 Z erd1 Naan (JOI19_naan) C++14
100 / 100
1722 ms 81144 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long lld;
typedef pair<lld, int> pli;
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
template<typename It>
ostream& _out(ostream& out, It b, It e){
    for(It i = b; i != e; i++){
        if(i != b)out << ' ';
        out << *i;
    }
}
template<typename T>
ostream& operator<<(ostream& out, vector<T>& v){
    return _out(out<<'[', all(v)) << ']';
}
template<typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> p){
    return out << '(' << p.ff << ", " << p.ss << ')';
}
vector<vector<int>> g;
vector<vector<pli>> v;
vector<int> perms;
vector<pli> ans;
vector<bool> used;
bool comp(pli a, pli b){
    if(a.ff/a.ss == b.ff/b.ss)
        return a.ff%a.ss*b.ss < b.ff%b.ss*a.ss;
    return a.ff/a.ss < b.ff/b.ss;
}
signed main(){
	int n, m;
	cin >> n >> m;
	g.resize(n), v.resize(n), used.resize(n);
	for(int i = 0; i < n; i++){
		int sum = 0;
		g[i].resize(m);
		for(int j = 0; j < m; j++){
			cin >> g[i][j];
			sum += g[i][j];
		}
		for(int j = 0, s = 0, k = 1; j < m; j++){
        while((lld)(s+g[i][j])*n >= (lld)k*sum)v[i].pb({(lld)k*sum-(lld)s*n+(lld)j*g[i][j]*n, g[i][j]*n}), k++; //(k*sum/n-s)/g[i][j]+j
			s += g[i][j];
		}
	}
	for(int i = 0; i < n; i++){
        pli minx = {LLONG_MAX, 1};
        int mini = 0;
        for(int j = 0; j < n; j++){
            if(used[j])continue;
            if(comp(v[j][i], minx))minx = v[j][i], mini = j;
        }
        used[mini] = true;
        perms.pb(mini+1), ans.pb(minx);
	}
	for(int i = 0; i < n-1; i++)cout << ans[i].ff << " " << ans[i].ss << endl;
	for(int i = 0; i < n; i++)cout << perms[i] << " ";
	cout <<endl;
}

Compilation message

naan.cpp: In function 'std::ostream& _out(std::ostream&, It, It)':
naan.cpp:15:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 5 ms 128 KB Output is correct
2 Correct 6 ms 376 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 6 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 6 ms 376 KB Output is correct
12 Correct 6 ms 376 KB Output is correct
13 Correct 6 ms 376 KB Output is correct
14 Correct 6 ms 376 KB Output is correct
15 Correct 7 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 280 KB Output is correct
2 Correct 6 ms 376 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 7 ms 376 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 6 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 6 ms 376 KB Output is correct
9 Correct 7 ms 376 KB Output is correct
10 Correct 7 ms 376 KB Output is correct
11 Correct 6 ms 408 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 6 ms 376 KB Output is correct
14 Correct 7 ms 376 KB Output is correct
15 Correct 7 ms 376 KB Output is correct
16 Correct 7 ms 376 KB Output is correct
17 Correct 7 ms 376 KB Output is correct
18 Correct 8 ms 376 KB Output is correct
19 Correct 7 ms 376 KB Output is correct
20 Correct 7 ms 376 KB Output is correct
21 Correct 7 ms 376 KB Output is correct
22 Correct 8 ms 376 KB Output is correct
23 Correct 5 ms 256 KB Output is correct
24 Correct 8 ms 376 KB Output is correct
25 Correct 6 ms 376 KB Output is correct
26 Correct 6 ms 504 KB Output is correct
27 Correct 7 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 128 KB Output is correct
2 Correct 6 ms 376 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 6 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 6 ms 376 KB Output is correct
12 Correct 6 ms 376 KB Output is correct
13 Correct 6 ms 376 KB Output is correct
14 Correct 6 ms 376 KB Output is correct
15 Correct 7 ms 376 KB Output is correct
16 Correct 5 ms 280 KB Output is correct
17 Correct 6 ms 376 KB Output is correct
18 Correct 6 ms 376 KB Output is correct
19 Correct 7 ms 376 KB Output is correct
20 Correct 6 ms 376 KB Output is correct
21 Correct 6 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 6 ms 376 KB Output is correct
24 Correct 7 ms 376 KB Output is correct
25 Correct 7 ms 376 KB Output is correct
26 Correct 6 ms 408 KB Output is correct
27 Correct 5 ms 256 KB Output is correct
28 Correct 6 ms 376 KB Output is correct
29 Correct 7 ms 376 KB Output is correct
30 Correct 7 ms 376 KB Output is correct
31 Correct 7 ms 376 KB Output is correct
32 Correct 7 ms 376 KB Output is correct
33 Correct 8 ms 376 KB Output is correct
34 Correct 7 ms 376 KB Output is correct
35 Correct 7 ms 376 KB Output is correct
36 Correct 7 ms 376 KB Output is correct
37 Correct 8 ms 376 KB Output is correct
38 Correct 5 ms 256 KB Output is correct
39 Correct 8 ms 376 KB Output is correct
40 Correct 6 ms 376 KB Output is correct
41 Correct 6 ms 504 KB Output is correct
42 Correct 7 ms 380 KB Output is correct
43 Correct 131 ms 9208 KB Output is correct
44 Correct 761 ms 43004 KB Output is correct
45 Correct 545 ms 16632 KB Output is correct
46 Correct 87 ms 1804 KB Output is correct
47 Correct 603 ms 24440 KB Output is correct
48 Correct 278 ms 64760 KB Output is correct
49 Correct 137 ms 17016 KB Output is correct
50 Correct 657 ms 74744 KB Output is correct
51 Correct 402 ms 30456 KB Output is correct
52 Correct 794 ms 67448 KB Output is correct
53 Correct 573 ms 61048 KB Output is correct
54 Correct 7 ms 376 KB Output is correct
55 Correct 88 ms 37880 KB Output is correct
56 Correct 487 ms 42744 KB Output is correct
57 Correct 389 ms 38136 KB Output is correct
58 Correct 490 ms 62072 KB Output is correct
59 Correct 462 ms 33912 KB Output is correct
60 Correct 1687 ms 81136 KB Output is correct
61 Correct 1713 ms 81144 KB Output is correct
62 Correct 1719 ms 80888 KB Output is correct
63 Correct 1722 ms 81112 KB Output is correct
64 Correct 1707 ms 81144 KB Output is correct
65 Correct 979 ms 81144 KB Output is correct
66 Correct 986 ms 81132 KB Output is correct
67 Correct 954 ms 81144 KB Output is correct
68 Correct 552 ms 43768 KB Output is correct
69 Correct 697 ms 39800 KB Output is correct
70 Correct 611 ms 54392 KB Output is correct
71 Correct 1006 ms 59512 KB Output is correct