//In the name of Allah :)
#include <bits/stdc++.h>
using namespace std;
string to_string(char c) { return string(1,c); }
string to_string(bool b) { return b ? "true" : "false"; }
string to_string(const char* s) { return (string)s; }
string to_string(string s) { return s; }
template<class A> string to_string(complex<A> c) {
stringstream ss; ss << c; return ss.str(); }
string to_string(vector<bool> v) {
string res = "{"; for(int i = 0; i < (int)v.size(); i++) res += char('0'+v[i]);
res += "}"; return res; }
template<size_t SZ> string to_string(bitset<SZ> b) {
string res = ""; for(size_t i = 0; i < SZ; i++) res += char('0'+b[i]);
return res; }
template<class A, class B> string to_string(pair<A,B> p);
template<class T> string to_string(T v) { // containers with begin(), end()
bool fst = 1; string res = "{";
for (const auto& x: v) {
if (!fst) res += ", ";
fst = 0; res += to_string(x);
}
res += "}"; return res;
}
template<class A, class B> string to_string(pair<A,B> p) {
return "("+to_string(p.first)+", "+to_string(p.second)+")"; }
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
cerr << to_string(h); if (sizeof...(t)) cerr << ", ";
DBG(t...); }
#ifdef LOCAL // compile with -DLOCAL
#define wis(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__)
#else
#define wis(...) 0
#endif
typedef long long ll;
typedef long double ld;
#define all(x) (x).begin(), (x).end()
const int MAXN = 2010;
int n, m, a[MAXN][MAXN];
bitset<MAXN> mark;
vector<int> out;
struct frac {
ll x, y;
frac () {
x = 0, y = 1;
}
frac (ll _x, ll _y) {
x = _x;
y = _y;
}
inline bool operator < (const frac& he) {
return (ld) x * he.y < (ld) he.x * y;
}
};
vector<frac> where[MAXN];
int main() {
ios::sync_with_stdio(0);
#ifndef LOCAL
cin.tie(0);
#endif
cin >> n >> m;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cin >> a[i][j];
}
}
for (int i = 0; i < n; ++i) {
ll s = 0;
for (int j = 0; j < m; ++j) {
s += a[i][j];
}
int pos = 0;
ll cur = 0;
for (int j = 1; j < n; ++j) {
while (n * (cur + a[i][pos]) < s * j) {
cur += a[i][pos];
pos++;
}
ll x = j * s - cur * n, y = n * a[i][pos];
frac p(x + pos * y, y);
where[i].push_back(p);
}
}
for (int i = 0; i < n - 1; ++i) {
int p = -1;
for (int j = 0; j < n; ++j) {
if (mark[j]) {
continue;
}
if (p == -1) {
p = j;
continue;
}
if (where[j][i] < where[p][i]) {
p = j;
}
}
mark[p] = 1;
cout << where[p][i].x << ' ' << where[p][i].y << '\n';
out.push_back(p + 1);
}
for (int i : out) {
cout << i << ' ';
}
for (int i = 0; i < n; ++i) {
if (!mark[i]) {
cout << i + 1 << '\n';
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
380 KB |
Output is correct |
3 |
Correct |
1 ms |
356 KB |
Output is correct |
4 |
Correct |
1 ms |
372 KB |
Output is correct |
5 |
Correct |
1 ms |
368 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
408 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
372 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
408 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
1 ms |
380 KB |
Output is correct |
16 |
Correct |
1 ms |
376 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
376 KB |
Output is correct |
19 |
Correct |
1 ms |
400 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
368 KB |
Output is correct |
24 |
Correct |
1 ms |
460 KB |
Output is correct |
25 |
Correct |
1 ms |
368 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
380 KB |
Output is correct |
3 |
Correct |
1 ms |
356 KB |
Output is correct |
4 |
Correct |
1 ms |
372 KB |
Output is correct |
5 |
Correct |
1 ms |
368 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
408 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
372 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
408 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
460 KB |
Output is correct |
30 |
Correct |
1 ms |
380 KB |
Output is correct |
31 |
Correct |
1 ms |
376 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
376 KB |
Output is correct |
34 |
Correct |
1 ms |
400 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
1 ms |
368 KB |
Output is correct |
39 |
Correct |
1 ms |
460 KB |
Output is correct |
40 |
Correct |
1 ms |
368 KB |
Output is correct |
41 |
Correct |
1 ms |
364 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
33 ms |
12356 KB |
Output is correct |
44 |
Correct |
193 ms |
55784 KB |
Output is correct |
45 |
Correct |
113 ms |
23468 KB |
Output is correct |
46 |
Correct |
15 ms |
2592 KB |
Output is correct |
47 |
Correct |
137 ms |
31904 KB |
Output is correct |
48 |
Correct |
145 ms |
73156 KB |
Output is correct |
49 |
Correct |
44 ms |
20768 KB |
Output is correct |
50 |
Correct |
223 ms |
84516 KB |
Output is correct |
51 |
Correct |
111 ms |
33436 KB |
Output is correct |
52 |
Correct |
239 ms |
73524 KB |
Output is correct |
53 |
Correct |
185 ms |
69752 KB |
Output is correct |
54 |
Correct |
1 ms |
332 KB |
Output is correct |
55 |
Correct |
58 ms |
43608 KB |
Output is correct |
56 |
Correct |
142 ms |
46248 KB |
Output is correct |
57 |
Correct |
120 ms |
40712 KB |
Output is correct |
58 |
Correct |
164 ms |
69736 KB |
Output is correct |
59 |
Correct |
131 ms |
37444 KB |
Output is correct |
60 |
Correct |
402 ms |
84072 KB |
Output is correct |
61 |
Correct |
385 ms |
83844 KB |
Output is correct |
62 |
Correct |
391 ms |
83652 KB |
Output is correct |
63 |
Correct |
387 ms |
83916 KB |
Output is correct |
64 |
Correct |
389 ms |
83960 KB |
Output is correct |
65 |
Correct |
291 ms |
88880 KB |
Output is correct |
66 |
Correct |
289 ms |
88952 KB |
Output is correct |
67 |
Correct |
289 ms |
88980 KB |
Output is correct |
68 |
Correct |
143 ms |
52812 KB |
Output is correct |
69 |
Correct |
165 ms |
46788 KB |
Output is correct |
70 |
Correct |
167 ms |
64324 KB |
Output is correct |
71 |
Correct |
241 ms |
69768 KB |
Output is correct |