QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#744358#8992. Light UpsuryaaprakasshAC ✓1ms3820kbC++172.9kb2024-11-13 21:39:202024-11-13 21:39:22

Judging History

This is the latest submission verdict.

  • [2024-11-13 21:39:22]
  • Judged
  • Verdict: AC
  • Time: 1ms
  • Memory: 3820kb
  • [2024-11-13 21:39:20]
  • Submitted

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];

bool 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]=='?'){
			return 0;
		}
    if (v[k][j] != '.')
      break;
    vis[k][j] = 1;
  }
  for (int k = i + 1; k < n; k++) {
		if(v[k][j]=='?'){
			return 0;
		}
    if (v[k][j] != '.')
      break;
    vis[k][j] = 1;
  }
  for (int k = j - 1; k >= 0; k--) {
		if(v[i][k]=='?'){
			return 0;
		}
    if (v[i][k] != '.')
      break;
    vis[i][k] = 1;
  }
  for (int k = j + 1; k < n; k++) {
		if(v[i][k]=='?'){
			return 0;
		}
    if (v[i][k] != '.')
      break;
    vis[i][k] = 1;
  }

	return 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] == '?') {
        if(!dfs(i, j, n, v)){
					cout<<"0\n";
					return;
				}
      }
    }
  }
  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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3620kb

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: 1ms
memory: 3528kb

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: 3588kb

input:

1
?

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Accepted
time: 1ms
memory: 3812kb

input:

1
0

output:

1

result:

ok single line: '1'

Test #5:

score: 0
Accepted
time: 1ms
memory: 3608kb

input:

1
1

output:

0

result:

ok single line: '0'

Test #6:

score: 0
Accepted
time: 1ms
memory: 3768kb

input:

2
0.
.?

output:

1

result:

ok single line: '1'

Test #7:

score: 0
Accepted
time: 1ms
memory: 3612kb

input:

2
2?
?.

output:

1

result:

ok single line: '1'

Test #8:

score: 0
Accepted
time: 1ms
memory: 3612kb

input:

3
..?
.0.
?..

output:

1

result:

ok single line: '1'

Test #9:

score: 0
Accepted
time: 1ms
memory: 3612kb

input:

3
..?
.0.
?.?

output:

0

result:

ok single line: '0'

Test #10:

score: 0
Accepted
time: 1ms
memory: 3820kb

input:

3
?..
.2.
..?

output:

0

result:

ok single line: '0'

Test #11:

score: 0
Accepted
time: 1ms
memory: 3548kb

input:

10
.1?20.1?3?
?22?2?.3?.
.?211..?21
..?2?2?2.?
.01..02.?3
...?2.?.3?
1.?3?12.?.
?.10.1?.11
2?......2?
...?.00.?2

output:

1

result:

ok single line: '1'

Test #12:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

20
.....?10..2?.2?3?...
0..?...1..?3.?3?....
.?.1...?..2?21...?..
?3?2?2?2....?..00.?.
..1.......?12?....1.
0......?............
.?..0.0..?...01?.2?.
.....?.2?2.......?..
?1.....?.0...?......
...?1.......?4?..1..
.?....1.0....?3..?2.
1.?2?2?2.?..0.?2?3?.
?...2.2?..01.......?
1.01?.1....?........
......

output:

1

result:

ok single line: '1'

Test #13:

score: 0
Accepted
time: 1ms
memory: 3616kb

input:

30
.?....0.0..........?..........
?2.?.....0........?2...?....0.
.......?...............2...?..
0..1?1...0.?....1?...0.?..01..
............?..............1.?
0.?.........2...........?.1?..
...1..?....1?.....1..?........
...?3?3...........?.0.?...0...
.?13?3?.............0....?...0
.21?..1..?3?1...?....

output:

1

result:

ok single line: '1'

Test #14:

score: 0
Accepted
time: 0ms
memory: 3532kb

input:

30
?.............................
.?............................
..?...........................
...?..........................
....?.........................
.....?........................
......?.......................
.......?......................
........?.....................
.........?...........

output:

1

result:

ok single line: '1'

Test #15:

score: 0
Accepted
time: 0ms
memory: 3492kb

input:

30
X?X?X?X?X?X?X?X?X?X?X?X?X?X?X?
?X?X?X?X?X?X?X?X?X?X?X?X?X?X?X
X?X?X?X?X?X?X?X?X?X?X?X?X?X?X?
?X?X?X?X?X?X?X?X?X?X?X?X?X?X?X
X?X?X?X?X?X?X?X?X?X?X?X?X?X?X?
?X?X?X?X?X?X?X?X?X?X?X?X?X?X?X
X?X?X?X?X?X?X?X?X?X?X?X?X?X?X?
?X?X?X?X?X?X?X?X?X?X?X?X?X?X?X
X?X?X?X?X?X?X?X?X?X?X?X?X?X?X?
?X?X?X?X?X?X?X?X?X...

output:

1

result:

ok single line: '1'

Test #16:

score: 0
Accepted
time: 0ms
memory: 3780kb

input:

30
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000000000000000
000000000000000000...

output:

1

result:

ok single line: '1'

Test #17:

score: 0
Accepted
time: 0ms
memory: 3812kb

input:

3
.?.
?4?
.?.

output:

1

result:

ok single line: '1'

Test #18:

score: 0
Accepted
time: 0ms
memory: 3544kb

input:

19
XXXXXXXXX?XXX?XXX?X
X0XXX1?XX2XX?3XX?4?
XXXXXXXXX?XXX?XXX?X
XXXXXXXXXXXXXXXXXXX
XXXXX?XXXXXXX?XXX?X
X0XXX1XX?2XX?3?X?4?
XXXXXXXXX?XXXXXXX?X
XXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXX?X
X0XX?1XX?2?X?3?X?4?
XXXXXXXXXXXXX?XXX?X
XXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXX?XXX?X
X0XXX1XXX2?XX3?X?4?
XXXXX?XXX?XXX?XXX...

output:

1

result:

ok single line: '1'

Test #19:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

19
XXXXXXXXX?XXX?XXX?X
X0XXX1?XX2XX?3XX?4?
XXXXXXXXX?XXX?XXX?X
XXXXXXXXXXXXXXXXXXX
XXXXX?XXXXXXX?XXX?X
X0XXX1XX?2XX?3?X?4?
XXXXXXXXX?XXXXXXX?X
XXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXX?X
X0XX?1XX?2?X?3?X?4?
XXXXX?XXXXXXX?XXX?X
XXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXX?XXX?X
X0XXX1XXX2?XX3?X?4?
XXXXX?XXX?XXX?XXX...

output:

0

result:

ok single line: '0'

Test #20:

score: 0
Accepted
time: 0ms
memory: 3780kb

input:

19
XXXXXXXXX?XXX?XXX?X
X0XXX1?XX2XX?3XX?4?
XXXXXXXXX?XXX?XXX?X
XXXXXXXXXXXXXXXXXXX
XXXXX?XXXXXXX?XXX?X
X0XXX1XX?2XX?3?X?4?
XXXXXXXXX?XXXXXXX?X
XXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXX?X
X0XX?1XX?2?X?3?X?4?
XXXXXXXXXXXXX?XXX?X
XXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXX?XXX?X
X0XXX1XXX2XXX3?X?4?
XXXXX?XXX?XXX?XXX...

output:

0

result:

ok single line: '0'

Test #21:

score: 0
Accepted
time: 0ms
memory: 3748kb

input:

19
XXXXXXXXX?XXX?XXX?X
X0XXX1?XX2XX?3XX?4?
XXXXXXXXX?XXX?XXX?X
XXXXXXXXXXXXXXXXXXX
XXXXX?XXXXXXX?XXX?X
X0XXX1XX?2XX?3?X?4?
XXXXXXXXX?XXXXXXX?X
XXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXX?X
X0XX?1XX?2?X?3?X?4?
XXXXXXXXXXXXX?XXX?X
XXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXX?XXX?X
X0XXX1XXX2?XX3?X?4?
XXXXX?XXX?XXX?XXX...

output:

0

result:

ok single line: '0'

Test #22:

score: 0
Accepted
time: 0ms
memory: 3532kb

input:

19
XXXXXXXXX?XXX?XXX?X
X0XXX1?XX2XX?3XX?4?
XXXXXXXXX?XXX?XXX?X
XXXXXXXXXXXXXXXXXXX
XXXXX?XXXXXXX?XXX?X
X0XXX1XX?2XX?3?X?4?
XXXXXXXXX?XXXXXXX?X
XXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXX?X
X0XX?1XX?2?X?3?X?4?
XXXXXXXXXXXXX?XXX?X
XXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXX?XXX?X
X0XXX1XXX2?XX3?X?4?
XXXXX?XXX?XXX?XXX...

output:

0

result:

ok single line: '0'

Test #23:

score: 0
Accepted
time: 0ms
memory: 3512kb

input:

19
XXXXXXXXX?XXX?XXX?X
X0XXX1?XX2XX?3XX?4?
X?XXXXXXX?XXX?XXX?X
XXXXXXXXXXXXXXXXXXX
XXXXX?XXXXXXX?XXX?X
X0XXX1XX?2XX?3?X?4?
XXXXXXXXX?XXXXXXX?X
XXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXX?X
X0XX?1XX?2?X?3?X?4?
XXXXXXXXXXXXX?XXX?X
XXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXX?XXX?X
X0XXX1XXX2?XX3?X?4?
XXXXX?XXX?XXX?XXX...

output:

0

result:

ok single line: '0'