Task: | Grid |
Sender: | Kaban-5 |
Submission time: | 2017-01-20 18:08:07 +0200 |
Language: | C++ |
Status: | READY |
Result: | 35 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 35 |
#2 | TIME LIMIT EXCEEDED | 0 |
#3 | TIME LIMIT EXCEEDED | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.04 s | 1 | details |
#2 | ACCEPTED | 0.03 s | 1 | details |
#3 | ACCEPTED | 0.03 s | 1 | details |
#4 | ACCEPTED | 0.03 s | 1 | details |
#5 | ACCEPTED | 0.05 s | 1 | details |
#6 | ACCEPTED | 0.05 s | 1 | details |
#7 | ACCEPTED | 0.03 s | 1 | details |
#8 | ACCEPTED | 0.03 s | 1 | details |
#9 | ACCEPTED | 0.04 s | 1 | details |
#10 | ACCEPTED | 0.04 s | 2 | details |
#11 | ACCEPTED | 0.04 s | 2 | details |
#12 | ACCEPTED | 0.13 s | 2 | details |
#13 | TIME LIMIT EXCEEDED | -- | 2 | details |
#14 | TIME LIMIT EXCEEDED | -- | 2 | details |
#15 | TIME LIMIT EXCEEDED | -- | 2 | details |
#16 | ACCEPTED | 0.04 s | 3 | details |
#17 | ACCEPTED | 0.05 s | 3 | details |
#18 | TIME LIMIT EXCEEDED | -- | 3 | details |
#19 | TIME LIMIT EXCEEDED | -- | 3 | details |
#20 | TIME LIMIT EXCEEDED | -- | 3 | details |
#21 | TIME LIMIT EXCEEDED | -- | 3 | details |
Code
//#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define fst first #define snd second #define forn(i, n) for (int i = 0; i < int(n); ++i) typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vll; typedef pair<int, int> pii; typedef vector<pii> vii; #define sz(c) (int)(c).size() #define ALL(c) (c).begin(), (c).end() bool check (const vvi &v) { const int n = sz(v); vi sums(2 * n); forn (i, n) forn (j, n) { sums[i] += v[i][j]; sums[n + j] += v[i][j]; } sort(ALL(sums)); return unique(ALL(sums)) == sums.end(); } void solve (int n) { vi nums(n * n); forn (i, n) forn (j, n) nums[i * n + j] = i + 1; mt19937 rng; if (n <= 3) { cout << "QAQ" << endl; return; } vvi mat(n, vi(n)); shuffle(ALL(nums), rng); forn (i, n) forn (j, n) mat[i][j] = nums[i * n + j]; while (true) { if (!check(mat)) { for (int it = 0; it < 1; it++) { int x = rng() % (n * n); int y = rng() % (n * n); swap(mat[x / n][x % n], mat[y / n][y % n]); } continue; } forn (i, n) { forn (j, n) cout << mat[i][j] << " \n"[j + 1 == n]; } return; } forn (i, n) forn (j, n) if (j != i) mat[i][j] = i + 1; forn (i, (n - (n & 1))) mat[i][i] = (n - (n & 1) - i); vi p(n); iota(ALL(p), 0); while (true) { shuffle(ALL(p), rng); forn (i, n) mat[i][i] = p[i]; if (check(mat)) { forn (i, n) { forn (j, n) cout << mat[i][j] << ' '; cout << '\n'; } return; } } } int main() { #ifndef ONLINE_JUDGE //freopen("input.txt", "rt", stdin); //freopen("output.txt", "w", stdout); #endif // ONLINE_JUDGE ios_base::sync_with_stdio(false); cin.tie(0); int n; while (cin >> n) solve(n); }
Test details
Test 1
Group: 1
Verdict: ACCEPTED
input |
---|
2 |
correct output |
---|
QAQ |
user output |
---|
QAQ |
Test 2
Group: 1
Verdict: ACCEPTED
input |
---|
3 |
correct output |
---|
QAQ |
user output |
---|
QAQ |
Test 3
Group: 1
Verdict: ACCEPTED
input |
---|
4 |
correct output |
---|
3 4 3 4 3 1 1 2 4 4 3 2 2 2 1 1 |
user output |
---|
2 1 1 1 4 2 3 4 4 2 3 3 4 2 1 3 |
Test 4
Group: 1
Verdict: ACCEPTED
input |
---|
5 |
correct output |
---|
2 3 4 1 1 3 4 2 1 2 4 2 3 1 3 4 3 2 1 4 5 5 5 5 5 |
user output |
---|
2 3 3 5 1 1 2 3 4 2 1 2 2 3 1 1 5 4 4 4 5 3 4 5 5 |
Test 5
Group: 1
Verdict: ACCEPTED
input |
---|
6 |
correct output |
---|
2 3 4 5 1 1 3 4 5 2 1 2 4 5 2 3 1 3 5 2 3 4 1 4 5 4 3 2 1 5 ... |
user output |
---|
1 1 4 3 6 1 4 4 3 2 6 2 5 5 6 3 2 2 1 4 2 1 6 3 6 4 6 5 5 3 ... |
Test 6
Group: 1
Verdict: ACCEPTED
input |
---|
7 |
correct output |
---|
2 3 4 5 6 1 1 3 4 5 6 2 1 2 4 5 6 2 3 1 3 5 6 2 3 4 1 4 6 2 3 4 5 1 5 ... |
user output |
---|
5 3 5 7 1 5 6 6 3 1 6 4 3 4 2 3 7 6 7 4 7 4 5 5 7 6 1 6 6 1 2 5 4 3 2 ... |
Test 7
Group: 1
Verdict: ACCEPTED
input |
---|
8 |
correct output |
---|
2 3 4 5 6 7 1 1 3 4 5 6 7 2 1 2 4 5 6 7 2 3 1 3 5 6 7 2 3 4 1 4 6 7 2 3 4 5 1 5 ... |
user output |
---|
2 6 4 2 8 4 1 5 6 6 4 7 7 4 8 6 1 3 5 4 3 5 1 2 2 7 4 8 2 4 1 7 6 6 6 7 7 2 8 8 ... |
Test 8
Group: 1
Verdict: ACCEPTED
input |
---|
9 |
correct output |
---|
2 3 4 5 6 7 8 1 1 3 4 5 6 7 8 2 1 2 4 5 6 7 8 2 3 1 3 5 6 7 8 2 3 4 1 4 6 7 8 2 3 4 5 1 5 ... |
user output |
---|
9 2 4 2 4 2 8 3 4 2 4 5 9 9 7 1 2 6 8 2 5 1 2 3 5 3 3 6 9 7 2 8 5 3 6 6 8 1 5 8 7 8 4 1 4 ... |
Test 9
Group: 1
Verdict: ACCEPTED
input |
---|
10 |
correct output |
---|
2 3 4 5 6 7 8 9 1 1 3 4 5 6 7 8 9 2 1 2 4 5 6 7 8 9 2 3 1 3 5 6 7 8 9 2 3 4 1 4 6 7 8 9 2 3 4 5 1 5 ... |
user output |
---|
7 6 8 9 2 3 3 10 9 1 8 2 7 5 10 10 3 10 8 2 4 2 8 7 8 6 10 1 7 9 2 1 6 9 6 7 2 3 9 10 1 5 8 1 4 3 10 6 4 5 ... |
Test 10
Group: 2
Verdict: ACCEPTED
input |
---|
3 |
correct output |
---|
QAQ |
user output |
---|
QAQ |
Test 11
Group: 2
Verdict: ACCEPTED
input |
---|
4 |
correct output |
---|
3 4 3 4 3 1 1 2 4 4 3 2 2 2 1 1 |
user output |
---|
2 1 1 1 4 2 3 4 4 2 3 3 4 2 1 3 |
Test 12
Group: 2
Verdict: ACCEPTED
input |
---|
29 |
correct output |
---|
2 3 4 5 6 7 8 9 10 11 12 13 14... |
user output |
---|
17 4 16 2 13 2 10 16 18 29 15 ... |
Test 13
Group: 2
Verdict: TIME LIMIT EXCEEDED
input |
---|
48 |
correct output |
---|
2 3 4 5 6 7 8 9 10 11 12 13 14... |
user output |
---|
(empty) |
Test 14
Group: 2
Verdict: TIME LIMIT EXCEEDED
input |
---|
80 |
correct output |
---|
2 3 4 5 6 7 8 9 10 11 12 13 14... |
user output |
---|
(empty) |
Test 15
Group: 2
Verdict: TIME LIMIT EXCEEDED
input |
---|
97 |
correct output |
---|
2 3 4 5 6 7 8 9 10 11 12 13 14... |
user output |
---|
(empty) |
Test 16
Group: 3
Verdict: ACCEPTED
input |
---|
3 |
correct output |
---|
QAQ |
user output |
---|
QAQ |
Test 17
Group: 3
Verdict: ACCEPTED
input |
---|
4 |
correct output |
---|
3 4 3 4 3 1 1 2 4 4 3 2 2 2 1 1 |
user output |
---|
2 1 1 1 4 2 3 4 4 2 3 3 4 2 1 3 |
Test 18
Group: 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
111 |
correct output |
---|
2 3 4 5 6 7 8 9 10 11 12 13 14... |
user output |
---|
(empty) |
Test 19
Group: 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
506 |
correct output |
---|
2 3 4 5 6 7 8 9 10 11 12 13 14... |
user output |
---|
(empty) |
Test 20
Group: 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
844 |
correct output |
---|
2 3 4 5 6 7 8 9 10 11 12 13 14... |
user output |
---|
(empty) |
Test 21
Group: 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
991 |
correct output |
---|
2 3 4 5 6 7 8 9 10 11 12 13 14... |
user output |
---|
(empty) |