| Task: | Ruudukko |
| Sender: | while(false) |
| Submission time: | 2017-01-19 15:16:37 +0200 |
| Language: | C++ |
| Status: | READY |
| Result: | 0 |
| group | verdict | score |
|---|---|---|
| #1 | TIME LIMIT EXCEEDED | 0 |
| #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.04 s | 1 | details |
| #4 | ACCEPTED | 0.03 s | 1 | details |
| #5 | ACCEPTED | 0.87 s | 1 | details |
| #6 | TIME LIMIT EXCEEDED | -- | 1 | details |
| #7 | TIME LIMIT EXCEEDED | -- | 1 | details |
| #8 | TIME LIMIT EXCEEDED | -- | 1 | details |
| #9 | TIME LIMIT EXCEEDED | -- | 1 | details |
| #10 | ACCEPTED | 0.04 s | 2 | details |
| #11 | ACCEPTED | 0.03 s | 2 | details |
| #12 | TIME LIMIT EXCEEDED | -- | 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.04 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
#include <iostream>
using namespace std;
int n;
int sumX[1000];
int sumY[1000];
int grid[1000][1000];
int num[1001];
int search(int x, int y, int a);
bool many(int s);
int main(){
cin >> n;
for (int i=0;i<n;i++){
sumX[i]=0;
sumY[i]=0;
num[i]=0;
}
for (int i=1;i<=n;i++){
if (search(0,0,i)) return 0;
}
cout << "QAQ";
return 0;
}
int search(int x, int y, int a){
grid[x][y]=a;
num[a]++;
sumX[x]+=a;
sumY[y]+=a;
if ((num[a]<=n)&&(y!=n-1||!many(sumX[x]))&&(x!=n-1||!many(sumY[y]))){
if (x!=n-1) {for (int i=1;i<=n;i++){
if (search(x+1,y,i)) return 1;
}}
else if (y!=n-1) {for (int i=1;i<=n;i++){
if (search(0,y+1,i)) return 1;
}}
else {
for (int i=0;i<n;i++){
for (int j=0;j<n;j++){cout << grid[i][j] << ' ';}
cout << '\n';
}
return 1;
}
}
grid[x][y]=0;
num[a]--;
sumX[x]-=a;
sumY[y]-=a;
return 0;
}
bool many(int s){
bool t=false;
for (int i=0;i<n;i++){
if (sumX[i]==s){
if (t){return true;}
t=true;
}
if (sumY[i]==s){
if (t){return true;}
t=true;
}
}
return false;
}
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 3 4 3 2 2 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 2 3 3 4 1 2 3 3 5 1 2 3 4 5 1 2 4 5 4 1 2 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 2 3 4 4 4 1 2 3 5 6 6 1 2 3 3 4 4 1 2 3 5 5 5 1 2 3 5 5 6 ... |
Test 6
Group: 1
Verdict: TIME LIMIT EXCEEDED
| 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 |
|---|
| (empty) |
Test 7
Group: 1
Verdict: TIME LIMIT EXCEEDED
| 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 |
|---|
| (empty) |
Test 8
Group: 1
Verdict: TIME LIMIT EXCEEDED
| 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 |
|---|
| (empty) |
Test 9
Group: 1
Verdict: TIME LIMIT EXCEEDED
| 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 |
|---|
| (empty) |
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 3 4 3 2 2 4 4 |
Test 12
Group: 2
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 29 |
| correct output |
|---|
| 2 3 4 5 6 7 8 9 10 11 12 13 14... |
| user output |
|---|
| (empty) |
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 |
|---|
| 1 1 2 3 1 2 3 4 1 3 4 3 2 2 4 4 |
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) |
