QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#677342 | #4079. 칠하기 | Matutino | 0 | 1ms | 7836kb | C++17 | 1.5kb | 2024-10-26 11:27:22 | 2024-10-26 11:27:22 |
answer
#include<bits/stdc++.h>
#define reg register
inline bool cmin(reg int &x,reg int y){return x>y?x=y,1:0;}
const int N=1010;
int dx[]={0,-1,0,1},dy[]={-1,0,1,0};
int id[2][N][N],cnt,tot;
int bel[N],dfn[N],dfc,vis[N],stk[N],tp,in[N],low[N];
std::vector<int> G[N],G2[N];
void tar(reg int u){
dfn[u]=low[u]=++dfc,vis[stk[++tp]=u]=1;
for (auto v:G[u]) if (!dfn[v]) tar(v),cmin(low[u],low[v]);
else if (vis[v]) cmin(low[u],dfn[v]);
if (low[u]==dfn[u]){
++tot;
do bel[stk[tp]]=tot,vis[stk[tp]]=0; while (stk[tp--]^u);
}
}
int yellowblue(int n,int m,std::vector<std::string> V){
auto chk=[&](reg int x,reg int y)->bool {return 0<=x&&x<n&&0<=y&&y<m&&V[x][y]=='.';};
for (reg int k=0;k<2;k++) for (reg int i=0;i<n;i++) for (reg int j=0;j<m;j++) if (V[i][j]=='.')
id[k][i][j]=chk(i+dx[k],j+dy[k])?id[k][i+dx[k]][j+dy[k]]:++cnt;
for (reg int k=0;k<2;k++) for (reg int i=0;i<n;i++) for (reg int j=0;j<m;j++) if (V[i][j]=='.')
if (!chk(i+dx[k],j+dy[k])||!chk(i+dx[k+2],j+dy[k+2])) G[id[k][i][j]].push_back(id[k^1][i][j]);
for (reg int i=1;i<=cnt;i++) if (!dfn[i]) tar(i);
for (reg int u=1;u<=cnt;u++) for (auto v:G[u]) if (bel[u]^bel[v]) G2[bel[u]].push_back(bel[v]),in[bel[v]]++;
std::vector<int> ord; std::queue<int> q;
for (reg int i=1;i<=tot;i++) if (!in[i]) q.push(i);
while (!q.empty()){
reg int u=q.front(); q.pop(),ord.push_back(u);
for (auto v:G2[u]) if (!(--in[v])) q.push(v);
}
for (reg int i=0;i+1<ord.size();i++){
reg int flg=0;
for (auto v:G2[ord[i]]) flg|=v==ord[i+1];
if (!flg) return 0;
}
return 1;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 30
Accepted
time: 1ms
memory: 5628kb
input:
3 5 ...## ....# #.#..
output:
1
result:
ok single line: '1'
Test #2:
score: 30
Accepted
time: 1ms
memory: 5708kb
input:
4 4 ..#. #... ...# .#..
output:
1
result:
ok single line: '1'
Test #3:
score: 30
Accepted
time: 1ms
memory: 5740kb
input:
15 15 #######..###### ######....##### #####......#### ####........### ###..........## ##............# #.............. ............... #.............# ##...........## ###.........### ####.......#### #####.....##### ######...###### #######.#######
output:
1
result:
ok single line: '1'
Test #4:
score: 30
Accepted
time: 1ms
memory: 5812kb
input:
16 16 ########..###### #######....##### ######......#### #####........### ####..........## ###............# ##.............. ................ ##.............# ###...........## ####.........### #####.......#### ######.....##### #######...###### ########.####### ########.#######
output:
0
result:
ok single line: '0'
Test #5:
score: 30
Accepted
time: 0ms
memory: 5768kb
input:
15 16 ########..###### #######....##### ######......#### #####........### ####..........## ###............# ##.............. ................ ##.............# ###...........## ####.........### #####.......#### ######.....##### #######...###### ########.#######
output:
1
result:
ok single line: '1'
Test #6:
score: 30
Accepted
time: 1ms
memory: 5936kb
input:
10 10 ..#...#... ...#...#.. .#...#...# #...#...#. ..#...#... ...#...#.. .#...#...# #...#...#. ..#...#... ...#...#..
output:
1
result:
ok single line: '1'
Test #7:
score: 30
Accepted
time: 1ms
memory: 5736kb
input:
10 10 ..#...#... ...#...#.. .#..#....# #.......#. .......#.. ..#....... .#.......# #....#..#. ..#...#... ...#...#..
output:
1
result:
ok single line: '1'
Test #8:
score: 30
Accepted
time: 0ms
memory: 7836kb
input:
20 20 ..#...#...#...#...#. #..#...#...#...#.... ....#...#...#...#..# ..#..#...#...#....#. .#....#...#...#..#.. #...#..#...#....#... ...#....#...#..#...# ..#...#..#....#...#. .#...#....#..#...#.. #...#...#...#...#... ...#...#...#...#...# ..#...#..#....#...#. .#...#....#..#...#.. #...#..#...#....#... ...
output:
0
result:
ok single line: '0'
Test #9:
score: 30
Accepted
time: 1ms
memory: 5724kb
input:
10 16 ..#..#..#..#..#. #..#..#..#..#... .#..#..#..#....# ..#..#..#....#.. #..#..#....#..#. .#..#....#..#..# ..#....#..#..#.. #....#..#..#..#. ...#..#..#..#..# .#..#..#..#..#..
output:
1
result:
ok single line: '1'
Test #10:
score: 0
Runtime Error
input:
50 45 ..#...##..##...#...#.#.#.....#..#..##..##.#.. ...#.#.#.#..##...###.#..##.##.#.....#......#. #......#.##.##....#.....#......#.#.#.#...#... .#.#####....##.#.#..###..#.##.###..#...#....# .....#.#.##.#..#..#...#.##...##..#...#....##. .#..#.....##..###...##....##..#...#.##.###... ..#.#.#.#..#.##.#....
output:
Unauthorized output
result:
Subtask #2:
score: 0
Skipped
Dependency #1:
0%