Task: | Grid |
Sender: | egor.lifar |
Submission time: | 2017-01-22 00:39:59 +0200 |
Language: | C++ |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 35 |
#2 | ACCEPTED | 21 |
#3 | ACCEPTED | 44 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.05 s | 1 | details |
#2 | ACCEPTED | 0.04 s | 1 | details |
#3 | ACCEPTED | 0.05 s | 1 | details |
#4 | ACCEPTED | 0.03 s | 1 | details |
#5 | ACCEPTED | 0.04 s | 1 | details |
#6 | ACCEPTED | 0.10 s | 1 | details |
#7 | ACCEPTED | 0.04 s | 1 | details |
#8 | ACCEPTED | 0.04 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.05 s | 2 | details |
#13 | ACCEPTED | 0.03 s | 2 | details |
#14 | ACCEPTED | 0.04 s | 2 | details |
#15 | ACCEPTED | 0.04 s | 2 | details |
#16 | ACCEPTED | 0.04 s | 3 | details |
#17 | ACCEPTED | 0.03 s | 3 | details |
#18 | ACCEPTED | 0.03 s | 3 | details |
#19 | ACCEPTED | 0.05 s | 3 | details |
#20 | ACCEPTED | 0.07 s | 3 | details |
#21 | ACCEPTED | 0.08 s | 3 | details |
Code
#include <iostream>#include <vector>#include <string>#include <algorithm>#include <cstdio>#include <numeric>#include <cstring>#include <ctime>#include <cstdlib>#include <set>#include <map>#include <unordered_map>#include <unordered_set>#include <list>#include <cmath>#include <bitset>#include <cassert>#include <queue>#include <stack>#include <deque>#include <cassert>using namespace std;template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }/** Interface */inline int readChar();template <class T = int> inline T readInt();template <class T> inline void writeInt( T x, char end = 0 );inline void writeChar( int x );inline void writeWord( const char *s );/** Read */static const int buf_size = 4096;inline int getChar() {static char buf[buf_size];static int len = 0, pos = 0;if (pos == len)pos = 0, len = fread(buf, 1, buf_size, stdin);if (pos == len)return -1;return buf[pos++];}inline int readChar() {int c = getChar();while (c <= 32)c = getChar();return c;}template <class T>inline T readInt() {int s = 1, c = readChar();T x = 0;if (c == '-')s = -1, c = getChar();while ('0' <= c && c <= '9')x = x * 10 + c - '0', c = getChar();return s == 1 ? x : -x;}/** Write */static int write_pos = 0;static char write_buf[buf_size];inline void writeChar( int x ) {if (write_pos == buf_size)fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;write_buf[write_pos++] = x;}template <class T>inline void writeInt( T x, char end ) {if (x < 0)writeChar('-'), x = -x;char s[24];int n = 0;while (x || !n)s[n++] = '0' + x % 10, x /= 10;while (n--)writeChar(s[n]);if (end)writeChar(end);}inline void writeWord( const char *s ) {while (*s)writeChar(*s++);}struct Flusher {~Flusher() {if (write_pos)fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;}} flusher;#define left left228#define right right228#define sz(c) (int)(c).size()#define all(c) (c).begin(), (c).end()int n;int a[1002][1002];int cnt[1002];int uk = 0;void get(int i, int j) {if (i == n - 2 && j == n) {set<int> s;for (int i = 0; i < n; i++) {int sum = 0;for (int j = 0; j < n; j++) {sum += a[i][j];}s.insert(sum);}for (int i = 0; i < n; i++) {int sum = 0;for (int j = 0; j < n; j++) {sum += a[j][i];}s.insert(sum);}if (sz(s) == 2 * n) {for (int i = 0; i < n; i++) {for (int j = 0; j < n; j++) {writeInt(a[i][j], ' ');}writeChar('\n');}exit(0);// for (int i = 0; i < n; i++) {// for (int j = 0; j < n; j++) {// //writeInt(a[i][j], ' ');// printf("%2d ", a[i][j]);// }// //writeChar('\n');// printf("\n");// }// exit(0);}return;}if (i < 0 || j >= n) {if (i < 0) {if (j != n) {get(j, 0);} else {get(n - 1, 1);}} else {get(n - 1, i + 2);}return;}for (int ii = 1; ii <= n; ii++) {if (cnt[ii] < n) {cnt[ii]++;a[i][j] = ii;get(i - 1, j + 1);cnt[ii]--;}}}int main() {cin >> n;if (n <= 13) {get(0, 0);cout << "QAQ" << endl;} else {// if (n % 4 == 1) {// cout << "QAQ" << endl;// return 0;// }int i = 0;int j = 0;int lst = 1;while (true) {if (i == n - 2 && j == n) {set<int> s;for (int i = 0; i < n; i++) {int sum = 0;for (int j = 0; j < n; j++) {sum += a[i][j];}s.insert(sum);}for (int i = 0; i < n; i++) {int sum = 0;for (int j = 0; j < n; j++) {sum += a[j][i];}s.insert(sum);}if (sz(s) != 2 * n) {cout << "QAQ" << endl;return 0;}for (int i = 0; i < n; i++) {for (int j = 0; j < n; j++) {writeInt(a[i][j], ' ');//printf("%2d ", a[i][j]);}writeChar('\n');// printf("\n");}return 0;}if (i < 0 || j >= n) {if (i < 0) {if (j != n) {i = j;j = 0;} else {i = n - 1;j = 1;}} else {j = i + 2;i = n - 1;}continue;}if (n % 4 == 3 && j == n - 1 && i == n / 2) {cnt[n]++;a[i][j] = n;//cout << "opa" << endl;i--, j++;continue;}if (n % 4 == 1 && j == n - 1 && i >= n / 2) {cnt[n]++;a[i][j] = n;//cout << "opa" << endl;i--, j++;continue;}if (n % 4 == 1 && i == n - 1 && j > n / 2) {cnt[n]++;a[i][j] = n;//cout << "opa" << endl;i--, j++;continue;}for (int ii = lst; ii <= n; ii++) {if (cnt[ii] < n) {cnt[ii]++;a[i][j] = ii;lst = ii;i--, j++;break;}}}}return 0;}
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 |
---|
1 1 2 3 1 2 3 4 1 2 4 4 2 3 4 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 |
---|
1 1 2 2 3 1 1 2 3 5 1 2 3 4 5 2 3 4 4 5 3 4 5 4 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 1 2 3 4 1 1 2 3 4 5 1 2 3 4 5 5 2 2 3 4 5 6 2 3 4 5 6 6 ... |
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 |
---|
1 1 1 2 3 3 4 1 1 2 2 3 4 6 1 2 2 3 4 5 6 1 2 3 4 5 6 7 2 3 4 5 6 6 7 ... |
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 |
---|
1 1 1 2 2 3 4 5 1 1 2 2 3 4 5 6 1 1 2 3 4 5 6 7 1 2 3 4 5 6 6 7 2 3 3 4 5 6 7 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 |
---|
1 1 1 2 2 3 4 4 5 1 1 1 2 3 3 4 5 6 1 1 2 3 3 4 5 6 7 1 2 2 3 4 5 6 7 8 2 2 3 4 5 6 7 8 9 ... |
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 |
---|
1 1 1 1 2 3 3 4 5 6 1 1 1 2 2 3 4 5 6 7 1 1 2 2 3 4 5 6 7 8 1 2 2 3 4 5 6 7 8 8 2 2 3 4 5 6 7 7 8 9 ... |
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 |
---|
1 1 2 3 1 2 3 4 1 2 4 4 2 3 4 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 |
---|
1 1 1 1 1 1 1 2 2 2 3 3 4 4 5 ... |
Test 13
Group: 2
Verdict: ACCEPTED
input |
---|
48 |
correct output |
---|
2 3 4 5 6 7 8 9 10 11 12 13 14... |
user output |
---|
1 1 1 1 1 1 1 1 1 2 2 2 2 3 3 ... |
Test 14
Group: 2
Verdict: ACCEPTED
input |
---|
80 |
correct output |
---|
2 3 4 5 6 7 8 9 10 11 12 13 14... |
user output |
---|
1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 ... |
Test 15
Group: 2
Verdict: ACCEPTED
input |
---|
97 |
correct output |
---|
2 3 4 5 6 7 8 9 10 11 12 13 14... |
user output |
---|
1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 ... |
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 |
---|
1 1 2 3 1 2 3 4 1 2 4 4 2 3 4 3 |
Test 18
Group: 3
Verdict: ACCEPTED
input |
---|
111 |
correct output |
---|
2 3 4 5 6 7 8 9 10 11 12 13 14... |
user output |
---|
1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 ... |
Test 19
Group: 3
Verdict: ACCEPTED
input |
---|
506 |
correct output |
---|
2 3 4 5 6 7 8 9 10 11 12 13 14... |
user output |
---|
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
Test 20
Group: 3
Verdict: ACCEPTED
input |
---|
844 |
correct output |
---|
2 3 4 5 6 7 8 9 10 11 12 13 14... |
user output |
---|
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
Test 21
Group: 3
Verdict: ACCEPTED
input |
---|
991 |
correct output |
---|
2 3 4 5 6 7 8 9 10 11 12 13 14... |
user output |
---|
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |