Task: | Grid |
Sender: | zscoder |
Submission time: | 2017-01-21 10:21:40 +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.04 s | 1 | details |
#2 | ACCEPTED | 0.04 s | 1 | details |
#3 | ACCEPTED | 0.04 s | 1 | details |
#4 | ACCEPTED | 0.03 s | 1 | details |
#5 | ACCEPTED | 0.04 s | 1 | details |
#6 | ACCEPTED | 0.03 s | 1 | details |
#7 | ACCEPTED | 0.04 s | 1 | details |
#8 | ACCEPTED | 0.03 s | 1 | details |
#9 | ACCEPTED | 0.03 s | 1 | details |
#10 | ACCEPTED | 0.04 s | 2 | details |
#11 | ACCEPTED | 0.03 s | 2 | details |
#12 | ACCEPTED | 0.04 s | 2 | details |
#13 | ACCEPTED | 0.04 s | 2 | details |
#14 | ACCEPTED | 0.03 s | 2 | details |
#15 | ACCEPTED | 0.04 s | 2 | details |
#16 | ACCEPTED | 0.04 s | 3 | details |
#17 | ACCEPTED | 0.04 s | 3 | details |
#18 | ACCEPTED | 0.05 s | 3 | details |
#19 | ACCEPTED | 0.09 s | 3 | details |
#20 | ACCEPTED | 0.11 s | 3 | details |
#21 | ACCEPTED | 0.15 s | 3 | details |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:182:9: warning: 'c' may be used uninitialized in this function [-Wmaybe-uninitialized] int r, c; ^
Code
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define fi first #define se second #define mp make_pair #define pb push_back #define fbo find_by_order #define ook order_of_key typedef long long ll; typedef pair<ll,ll> ii; typedef vector<int> vi; typedef long double ld; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; typedef set<int>::iterator sit; typedef map<int,int>::iterator mit; typedef vector<int>::iterator vit; int a[1001][1001]; int n; int cnt[1001]; int b[1001][1001]; bool check() { memset(cnt,0,sizeof(cnt)); set<int> s; for(int i = 0; i < n; i++) { int sum = 0; for(int j = 0; j < n; j++) { if(!(a[i][j]>=1&&a[i][j]<=n)) return 0; cnt[a[i][j]]++; sum+=a[i][j]; } s.insert(sum); //cerr<<sum<<' '; } //cerr<<'\n'; for(int j = 0; j < n; j++) { int sum = 0; for(int i = 0; i < n; i++) { sum+=a[i][j]; } s.insert(sum); //cerr<<sum<<' '; } //cerr<<'\n'; //cerr<<s.size()<<endl; if(!(int(s.size()) == 2*n)) return 0; for(int i = 1; i <= n; i++) if(!(cnt[i]==n)){return 0;} return 1; } void out() { for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { cout<<a[i][j]<<' '; } cout<<'\n'; } } void x2(int n) { for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { b[i][j] = a[i][j]; b[i][j+n] = a[i][j]; b[i+n][j] = a[i][j]+n; b[i+n][j+n] = a[n-1-i][n-1-j]+n; } } for(int i = 0; i < n*2; i++) { for(int j = 0; j < n*2; j++) { a[i][j]=b[i][j]; } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); srand(33); cin>>n; if(n<=3) { cout<<"QAQ"; return 0; } vi vec(n*n); for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { vec[i*n+j] = j+1; } } /* while(1) { random_shuffle(vec.begin(),vec.end()); for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { a[i][j] = vec[i*n+j]; } } if(check()) { //out(); break; } } while(cnt--) { x2(n); n<<=1; out(); assert(check()); } */ if(n==4) { cout<<"1 1 1 2\n1 2 3 4\n2 3 3 4\n2 3 4 4\n"; return 0; } int ptr = 0; for(int i = 0; i < n; i++) { a[0][i] = 1; } int cur = 2; for(int j = 0; j < n; j++) { for(int i = 1; i < n; i++) { ptr++; a[i][j] = cur; if(ptr>=n) { ptr=0; cur++; } } } vector<int> s1; for(int i = 0; i < n; i++) { int sum = 0; for(int j = 0; j < n; j++) { sum+=a[i][j]; } s1.pb(sum); } vi s2; for(int j = 0; j < n; j++) { int sum = 0; for(int i = 0; i < n; i++) { sum+=a[i][j]; } s2.pb(sum); } int r, c; for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { if(s1[i]==s2[j]) { r=i; c=j; break; } } } for(int i = max(0,n/2 - 2); i <= min(n - 1, n/2 + 2); i++) { swap(a[r][0],a[i][c]); if(check()) { cerr<<r<<' '<<0<<' '<<i<<' '<<c<<'\n'; out(); return 0; } swap(a[r][0],a[i][c]); } for(int i = max(0,n/2 - 2); i <= min(n - 1, n/2 + 2); i++) { swap(a[r][n-1],a[i][c]); if(check()) { cerr<<r<<' '<<n-1<<' '<<i<<' '<<c<<'\n'; out(); return 0; } swap(a[r][n-1],a[i][c]); } for(int i = max(0,n/2 - 2); i <= min(n - 1, n/2 + 2); i++) { swap(a[r][i],a[0][c]); if(check()) { cerr<<r<<' '<<i<<' '<<0<<' '<<c<<'\n'; out(); return 0; } swap(a[r][i],a[0][c]); } for(int i = max(0,n/2 - 2); i <= min(n - 1, n/2 + 2); i++) { swap(a[r][i],a[n-1][c]); if(check()) { cerr<<r<<' '<<i<<' '<<n-1<<' '<<c<<'\n'; out(); return 0; } swap(a[r][i],a[n-1][c]); } for(int i = 0; i < n; i++) { swap(a[r][0],a[i][c]); if(check()) { cerr<<r<<' '<<0<<' '<<i<<' '<<c<<'\n'; out(); return 0; } swap(a[r][0],a[i][c]); } for(int i = 0; i < n; i++) { swap(a[r][n-1],a[i][c]); if(check()) { cerr<<r<<' '<<n-1<<' '<<i<<' '<<c<<'\n'; out(); return 0; } swap(a[r][n-1],a[i][c]); } for(int i = 0; i < n; i++) { swap(a[r][i],a[0][c]); if(check()) { cerr<<r<<' '<<i<<' '<<0<<' '<<c<<'\n'; out(); return 0; } swap(a[r][i],a[0][c]); } for(int i = 0; i < n; i++) { swap(a[r][i],a[n-1][c]); if(check()) { cerr<<r<<' '<<i<<' '<<n-1<<' '<<c<<'\n'; out(); return 0; } swap(a[r][i],a[n-1][c]); } //swap(a[1][n-2],a[0][n-2]); //swap(a[n-1][0],a[n-1][n-2]); assert(0); out(); }
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 1 2 1 2 3 4 2 3 3 4 2 3 4 4 |
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 1 1 1 2 2 3 2 5 2 3 3 4 5 4 3 4 4 5 2 3 4 5 5 |
Error:
3 0 1 3
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 1 1 1 2 2 3 4 5 6 4 3 3 2 5 6 2 3 4 4 5 6 2 3 4 5 5 6 ... |
Error:
2 0 2 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 |
---|
1 1 1 1 1 1 1 2 2 3 4 5 6 7 2 3 3 4 2 6 7 2 3 4 4 5 6 7 2 3 4 5 5 6 7 ... |
Error:
5 0 2 4
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 1 1 1 1 1 2 2 3 4 5 6 7 8 2 3 3 4 5 6 7 8 5 3 4 4 2 6 7 8 2 3 4 5 5 6 7 8 ... |
Error:
3 0 3 4
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 1 1 1 1 1 1 2 2 3 4 5 6 7 8 9 2 3 3 4 5 6 7 8 9 2 3 4 4 5 2 7 8 9 2 3 4 5 5 6 7 8 9 ... |
Error:
7 0 3 5
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 1 1 1 1 1 1 2 2 3 4 5 6 7 8 9 10 2 3 3 4 5 6 7 8 9 10 2 3 4 4 5 6 7 8 9 10 6 3 4 5 5 2 7 8 9 10 ... |
Error:
4 0 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 |
---|
1 1 1 2 1 2 3 4 2 3 3 4 2 3 4 4 |
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 1 1 1 1 1 1 1 1 ... |
Error:
27 0 13 15
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 1 1 1 1 1 1 ... |
Error:
23 0 23 24
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 1 1 1 ... |
Error:
39 0 39 40
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 1 1 ... |
Error:
95 0 47 49
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 1 2 1 2 3 4 2 3 3 4 2 3 4 4 |
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 1 ... |
Error:
109 0 54 56
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 ... |
Error:
252 0 252 253
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 ... |
Error:
421 0 421 422
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 ... |
Error:
989 0 494 496