QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#744335 | #8992. Light Up | suryaaprakassh | WA | 0ms | 3808kb | C++17 | 2.7kb | 2024-11-13 21:34:19 | 2024-11-13 21:34:20 |
Judging History
answer
#include <bits/stdc++.h>
// pbds
/*#include <ext/pb_ds/assoc_container.hpp> // Common file*/
/*#include <ext/pb_ds/tree_policy.hpp>*/
/**/
/*using namespace __gnu_pbds;*/
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(x...) 42
#endif
#define fast_io \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define ll long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
/*typedef tree<int, null_type, less<int>, rb_tree_tag,*/
/* tree_order_statistics_node_update>*/
/* ordered_set;*/
int count(int x, int y, vector<string> &v) {
ll c = 0;
if (x - 1 >= 0) {
c += (v[x - 1][y] == '?');
}
if (x + 1 < v[0].size()) {
c += (v[x + 1][y] == '?');
}
if (y - 1 >= 0) {
c += (v[x][y - 1] == '?');
}
if (y + 1 < v.size()) {
c += (v[x][y + 1] == '?');
}
return c;
}
bool vis[35][35];
void dfs(int i, int j, int n, vector<string> &v) {
vis[i][j] = 1;
for (int k = i - 1; k >= 0; k--) {
if (v[k][j] != '.')
break;
vis[k][j] = 1;
}
for (int k = i + 1; k < n; k++) {
if (v[k][j] != '.')
break;
vis[k][j] = 1;
}
for (int k = j - 1; k >= 0; k--) {
if (v[i][k] != '.')
break;
vis[i][k] = 1;
}
for (int k = j + 1; k < n; k++) {
if (v[i][k] != '.')
break;
vis[i][k] = 1;
}
}
void solve() {
memset(vis, 0, sizeof vis);
ll n;
string a;
cin >> n;
vector<string> v;
for (int i = 0; i < n; i++) {
cin >> a;
v.push_back(a);
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (v[i][j] == '.' || v[i][j] == 'X')
continue;
if (isdigit(v[i][j]) && count(i, j, v) != (v[i][j] - '0')) {
cout << "0\n";
return;
}
if (v[i][j] == '?' && count(i, j, v) != 0) {
cout << "0\n";
return;
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (vis[i][j])
continue;
if (v[i][j] == '?') {
dfs(i, j, n, v);
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (v[i][j] == '.' and !vis[i][j]) {
cout << "0\n";
return;
}
}
}
cout << "1\n";
}
int main() {
fast_io;
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("output.txt", "w", stderr);
#endif
ll t = 1;
/*cin >> t;*/
while (t--) {
#ifdef LOCAL
cout << "TEST CASE " << t + 1 << "\n";
#endif
solve();
}
#ifdef LOCAL
cout << endl
<< "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec\n\n";
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3528kb
input:
7 .?.0..? ..X.1?. .X.?.2. .....?. ?3?..2. .?3.X?. ..?X?..
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3476kb
input:
7 .?.0..? ..X.1?. .X...2. .....?. ?3?..2. .?3.X?. ..?X?..
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
1 ?
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3808kb
input:
1 0
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
1 1
output:
0
result:
ok single line: '0'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
2 0. .?
output:
1
result:
ok single line: '1'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
2 2? ?.
output:
1
result:
ok single line: '1'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
3 ..? .0. ?..
output:
1
result:
ok single line: '1'
Test #9:
score: -100
Wrong Answer
time: 0ms
memory: 3612kb
input:
3 ..? .0. ?.?
output:
1
result:
wrong answer 1st lines differ - expected: '0', found: '1'