Task: | Grid |
Sender: | Xellos |
Submission time: | 2017-01-19 23:49:03 +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.03 s | 1 | details |
#2 | ACCEPTED | 0.03 s | 1 | details |
#3 | ACCEPTED | 0.03 s | 1 | details |
#4 | ACCEPTED | 0.04 s | 1 | details |
#5 | ACCEPTED | 0.05 s | 1 | details |
#6 | ACCEPTED | 0.05 s | 1 | details |
#7 | ACCEPTED | 0.04 s | 1 | details |
#8 | ACCEPTED | 0.05 s | 1 | details |
#9 | ACCEPTED | 0.06 s | 1 | details |
#10 | ACCEPTED | 0.04 s | 2 | details |
#11 | ACCEPTED | 0.04 s | 2 | details |
#12 | ACCEPTED | 0.04 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.06 s | 3 | details |
#20 | ACCEPTED | 0.15 s | 3 | details |
#21 | ACCEPTED | 0.16 s | 3 | details |
Code
#include <bits/stdc++.h> // iostream is too mainstream #include <cstdio> // bitch please #include <iostream> #include <algorithm> #include <cstdlib> #include <vector> #include <set> #include <map> #include <queue> #include <stack> #include <list> #include <cmath> #include <iomanip> #include <time.h> #define dibs reserve #define OVER9000 1234567890 #define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++) #define tisic 47 #define soclose 1e-8 #define chocolate win // so much chocolate #define patkan 9 #define ff first #define ss second #define abs(x) ((x < 0)?-(x):x) #define uint unsigned int #define dbl long double #define pi 3.14159265358979323846 using namespace std; // mylittledoge #ifdef DONLINE_JUDGE // palindromic tree is better than splay tree! #define lld I64d #endif /* Spurdo Spärde :DDDD SPEDE BEARD PEDRO SPORA PURJO PORE SPEARMINT PUDDING SPORO LORO PUDRO BARDE BENIS XDDDD :DDD XD */ int main() { cin.sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10); int N; cin >> N; if(N <= 3) {cout << "QAQ\n"; return 0;} srand(N); vector< vector<int> > ans(N,vector<int>(N)); vector<int> fr; for(int i =0; i < N; i++) for(int j =1; j <= N; j++) fr.push_back(j); for(int i =0; i < N; i++) for(int j =0; j < N; j++) { int x =rand()%fr.size(); swap(fr[fr.size()-1],fr[x]); ans[i][j] =fr.back(); fr.pop_back();} vector<int> sr(N,0),sc(N,0); map<int,set<int>> sums; for(int i =0; i < N; i++) { int s =0; for(int j =0; j < N; j++) s +=ans[i][j]; sums[s].insert(i+1); sr[i] =s; s =0; for(int j =0; j < N; j++) s +=ans[j][i]; sums[s].insert(-i-1); sc[i] =s;} set<int> n1p; ALL_THE(sums,it) if((it->ss).size() > 1) n1p.insert(it->ff); int st =0; if(N <= 11) { while(!n1p.empty()) { st++; for(int i =0; i < N; i++) for(int j =1; j <= N; j++) fr.push_back(j); for(int i =0; i < N; i++) for(int j =0; j < N; j++) { int x =rand()%fr.size(); swap(fr[fr.size()-1],fr[x]); ans[i][j] =fr.back(); fr.pop_back();} sums.clear(); for(int i =0; i < N; i++) { int s =0; for(int j =0; j < N; j++) s +=ans[i][j]; sums[s].insert(i+1); s =0; for(int j =0; j < N; j++) s +=ans[j][i]; sums[s].insert(-i-1);} n1p.clear(); ALL_THE(sums,it) if((it->ss).size() > 1) n1p.insert(it->ff); } // cout << st << "\n"; for(int i =0; i < N; i++) for(int j =0; j < N; j++) cout << ans[i][j] << ((j == N-1)?"\n":" "); return 0;} while(!n1p.empty()) { st++; int s1p =*n1p.begin(); int A =*(sums[s1p].begin()), B =*(sums[s1p].rbegin()); int Ar =max(0,A)-1, Ac =-min(0,A)-1, Br =max(0,B)-1, Bc =-min(0,B)-1; int Ax,Ay,Bx,By; if(Ar == -1) { Ay =Ac; Ax =rand()%N;} else { Ax =Ar; Ay =rand()%N;} if(Br == -1) { By =Bc; Bx =rand()%N;} else { Bx =Br; By =rand()%N;} sums[sr[Ax]].erase(Ax+1); sums[sc[Ay]].erase(-Ay-1); sums[sr[Bx]].erase(Bx+1); sums[sc[By]].erase(-By-1); if(sums[sr[Ax]].size() <= 1) n1p.erase(sr[Ax]); if(sums[sc[Ay]].size() <= 1) n1p.erase(sc[Ay]); if(sums[sr[Bx]].size() <= 1) n1p.erase(sr[Bx]); if(sums[sc[By]].size() <= 1) n1p.erase(sc[By]); sr[Ax] -=ans[Ax][Ay]; sc[Ay] -=ans[Ax][Ay]; sr[Bx] -=ans[Bx][By]; sc[By] -=ans[Bx][By]; swap(ans[Ax][Ay],ans[Bx][By]); sr[Ax] +=ans[Ax][Ay]; sc[Ay] +=ans[Ax][Ay]; sr[Bx] +=ans[Bx][By]; sc[By] +=ans[Bx][By]; sums[sr[Ax]].insert(Ax+1); sums[sc[Ay]].insert(-Ay-1); sums[sr[Bx]].insert(Bx+1); sums[sc[By]].insert(-By-1); if(sums[sr[Ax]].size() > 1) n1p.insert(sr[Ax]); if(sums[sc[Ay]].size() > 1) n1p.insert(sc[Ay]); if(sums[sr[Bx]].size() > 1) n1p.insert(sr[Bx]); if(sums[sc[By]].size() > 1) n1p.insert(sc[By]); } // cout << st << "\n"; for(int i =0; i < N; i++) for(int j =0; j < N; j++) cout << ans[i][j] << ((j == N-1)?"\n":" "); return 0;} // look at my code // my code is amazing
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 4 3 4 1 1 2 3 2 4 3 3 1 2 1 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 3 3 4 1 1 4 5 2 1 2 4 3 4 3 1 5 2 4 2 3 5 5 5 2 |
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 |
---|
2 1 4 5 3 4 6 5 6 3 5 2 6 3 6 5 1 4 2 4 4 5 5 6 3 2 3 3 2 1 ... |
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 |
---|
7 5 2 2 1 7 5 5 3 3 1 1 5 3 6 2 5 1 6 1 2 4 3 3 4 7 3 4 7 6 6 6 7 4 3 ... |
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 4 4 7 5 4 5 3 2 1 2 8 2 3 8 3 1 4 7 6 8 3 2 8 2 7 5 8 5 6 7 3 6 7 1 8 2 4 2 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 |
---|
5 7 9 2 6 4 5 1 9 7 7 8 6 9 7 3 6 8 7 2 2 3 2 4 4 7 6 8 3 5 2 1 1 7 9 9 1 2 5 3 5 7 3 8 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 |
---|
10 10 10 10 5 10 9 4 3 3 2 2 3 4 9 7 1 6 6 9 9 8 4 8 2 5 4 9 6 5 1 3 1 7 10 2 8 7 4 7 7 7 9 3 8 4 4 9 8 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 4 3 4 1 1 2 3 2 4 3 3 1 2 1 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 |
---|
15 3 15 29 6 15 26 24 8 11 21 ... |
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 |
---|
40 9 39 14 17 28 29 35 23 33 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 |
---|
36 24 53 33 65 2 33 62 27 2 67... |
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 |
---|
47 37 6 55 8 8 66 51 55 30 44 ... |
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 4 3 4 1 1 2 3 2 4 3 3 1 2 1 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 |
---|
66 63 54 92 42 5 18 88 83 30 9... |
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 |
---|
494 351 8 142 322 246 184 445 ... |
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 |
---|
24 264 73 551 575 350 617 808 ... |
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 |
---|
58 175 667 539 402 40 164 723 ... |