CSES - Datatähti Open 2017 - Results
Submission details
Task:Ice cream
Sender:egor.lifar
Submission time:2017-01-21 23:32:42 +0200
Language:C++
Status:READY
Result:0
Feedback
groupverdictscore
#10
Test results
testverdicttime
#10.04 sdetails
#20.04 sdetails
#30.04 sdetails
#40.04 sdetails
#50.03 sdetails
#60.05 sdetails
#70.05 sdetails
#80.03 sdetails
#90.04 sdetails
#100.06 sdetails

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, int lst) {
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);
}
return;
}
if (i < 0 || j >= n) {
if (i < 0) {
if (j != n) {
get(j, 0, lst);
} else {
get(n - 1, 1, lst);
}
} else {
get(n - 1, i + 2, lst);
}
return;
}
for (int ii = lst; ii <= n; ii++) {
if (cnt[ii] < n) {
cnt[ii]++;
a[i][j] = ii;
get(i - 1, j + 1, ii);
cnt[ii]--;
}
}
}
int main() {
cin >> n;
if (n <= 100) {
get(0, 0, 1);
cout << "QAQ" << endl;
} else {
int i = 0;
int j = 0;
int lst = 1;
while (true) {
if (i == n - 2 && j == n) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
writeInt(a[i][j], ' ');
}
writeChar('\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;
}
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

Verdict:

input
1 749
88 363

correct output
726

user output
QAQ

Test 2

Verdict:

input
2 902
968 550
152 228

correct output
456

user output
QAQ

Test 3

Verdict:

input
5 295
35 81
653 771
747 823
871 611
...

correct output
162

user output
QAQ

Test 4

Verdict:

input
10 272
38 13
114 420
42 344
942 307
...

correct output
840

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 5

Verdict:

input
50 468
867 254
870 736
28 739
60 609
...

correct output
2000

user output
1 1 1 1 1 1 1 1 1 2 2 2 2 3 3 ...

Test 6

Verdict:

input
100 739
395 712
476 916
102 614
312 533
...

correct output
1928

user output
1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 ...

Test 7

Verdict:

input
100 781
342 898
466 888
713 516
133 389
...

correct output
1894

user output
1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 ...

Test 8

Verdict:

input
100 297
423 506
135 31
279 441
362 969
...

correct output
1906

user output
1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 ...

Test 9

Verdict:

input
100 875
917 956
243 815
365 575
42 846
...

correct output
1960

user output
1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 ...

Test 10

Verdict:

input
100 651
963 307
169 423
172 150
779 998
...

correct output
1970

user output
1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 ...