QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#338443 | #4079. 칠하기 | hotboy2703 | 100 ✓ | 128ms | 124536kb | C++20 | 4.0kb | 2024-02-25 21:58:35 | 2024-02-25 21:58:36 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define pll pair <ll,ll>
#define fi first
#define se second
#define sz(a) (ll((a).size()))
#define BIT(mask,i) (((mask) >> (i))&1LL)
#define MASK(i) (1LL << (i))
#define MP make_pair
ll ptr=0;
const ll MAXN=1000;
ll row[MAXN+100][MAXN+100],col[MAXN+100][MAXN+100];
ll timeDFS;
stack <ll> s;
ll sz_comp;
ll in[MAXN*MAXN+100],out[MAXN*MAXN+100],low[MAXN*MAXN+100],comp[MAXN*MAXN+100];
bool deleted[MAXN*MAXN+100];
ll comp_out[MAXN*MAXN+100];
vector <ll> g[MAXN*MAXN+100];
vector <ll> comp_g[MAXN*MAXN+100];
ll order_comp[MAXN*MAXN+100];
void dfs(ll u){
in[u] = low[u] = ++timeDFS;
s.push(u);
for (auto v:g[u]){
if (!in[v]){
dfs(v);
low[u] = min(low[u],low[v]);
}
else{
if (!deleted[v])low[u] = min(low[u],in[v]);
}
}
out[u] = ++timeDFS;
if (low[u]==in[u]){
sz_comp++;
while (s.top()!=u){
comp[s.top()]=sz_comp;
deleted[s.top()]=1;
s.pop();
}
comp[s.top()]=sz_comp;
deleted[s.top()]=1;
s.pop();
}
}
int yellowblue(int n, int m, std::vector<std::string> s)
{
for (ll i = 0;i < n;i ++){
ll last = -1;
for (ll j = 0;j <= m;j ++){
if (j == m || s[i][j]=='#' ){
if (j-last>1){
ll tmp=++ptr;
for (ll k = last+1;k < j;k ++){
row[i][k] = tmp;
}
}
last=j;
}
}
}
for (ll j = 0;j < m;j ++){
ll last = -1;
for (ll i = 0;i <= n;i ++){
if (i==n||s[i][j]=='#'){
if (i-last>1){
ll tmp =++ptr;
for (ll k = last+1;k < i;k ++){
col[k][j] = tmp;
}
}
last=i;
}
}
}
for (ll i = 0;i < n;i ++){
ll last = -1;
for (ll j = 0;j <= m;j ++){
if (j == m || s[i][j]=='#'){
if (j-last>1){
g[row[i][last+1]].push_back(col[i][last+1]);
g[row[i][j-1]].push_back(col[i][j-1]);
}
last=j;
}
}
}
for (ll j = 0;j < m;j ++){
ll last = -1;
for (ll i = 0;i <= n;i ++){
if (i==n||s[i][j]=='#'){
if (i-last>1){
g[col[last+1][j]].push_back(row[last+1][j]);
g[col[i-1][j]].push_back(row[i-1][j]);
}
last=i;
}
}
}
// for (ll i = 0;i < n;i ++){
// for (ll j = 0;j < m;j ++){
// cout<<row[i][j];
// }
// cout<<'\n';
// }
// cout<<'\n';
// for (ll i = 0;i < n;i ++){
// for (ll j = 0;j < m;j ++){
// cout<<col[i][j];
// }
// cout<<'\n';
// }
// cout<<'\n';
// for (ll i = 1;i <= ptr;i ++){
// for (auto v:g[i]){
// cout<<i<<' '<<v<<endl;
// }
// }
for (ll i = 1;i <= ptr;i ++)if (!in[i])dfs(i);
// for (ll i = 1;i <= ptr;i ++)cout<<i<<' '<<in[i]<<' '<<low[i]<<endl;
// for (ll i = 1;i <= ptr;i ++)cout<<comp[i]<<' ';
// cout<<endl;
for (ll i = 1;i <= ptr;i ++){
comp_out[comp[i]] = max(comp_out[comp[i]],out[i]);
for (auto v:g[i]){
comp_g[comp[i]].push_back(comp[v]);
}
}
iota(order_comp+1,order_comp+1+sz_comp,1);
sort(order_comp+1,order_comp+1+sz_comp,[&](ll x,ll y){return comp_out[x]>comp_out[y];});
bool ok = 1;
for (ll i = 1;i + 1 <= sz_comp;i ++){
bool fail = 1;
for (auto v:comp_g[order_comp[i]]){
if (v==order_comp[i+1])fail = 0;
}
if (fail)ok=0;
}
return ok;
//return 1;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 30
Accepted
Test #1:
score: 30
Accepted
time: 0ms
memory: 11776kb
input:
3 5 ...## ....# #.#..
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 0ms
memory: 13824kb
input:
4 4 ..#. #... ...# .#..
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 0ms
memory: 11824kb
input:
15 15 #######..###### ######....##### #####......#### ####........### ###..........## ##............# #.............. ............... #.............# ##...........## ###.........### ####.......#### #####.....##### ######...###### #######.#######
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 3ms
memory: 11744kb
input:
16 16 ########..###### #######....##### ######......#### #####........### ####..........## ###............# ##.............. ................ ##.............# ###...........## ####.........### #####.......#### ######.....##### #######...###### ########.####### ########.#######
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 3ms
memory: 13788kb
input:
15 16 ########..###### #######....##### ######......#### #####........### ####..........## ###............# ##.............. ................ ##.............# ###...........## ####.........### #####.......#### ######.....##### #######...###### ########.#######
output:
1
result:
ok single line: '1'
Test #6:
score: 0
Accepted
time: 0ms
memory: 13848kb
input:
10 10 ..#...#... ...#...#.. .#...#...# #...#...#. ..#...#... ...#...#.. .#...#...# #...#...#. ..#...#... ...#...#..
output:
1
result:
ok single line: '1'
Test #7:
score: 0
Accepted
time: 0ms
memory: 11800kb
input:
10 10 ..#...#... ...#...#.. .#..#....# #.......#. .......#.. ..#....... .#.......# #....#..#. ..#...#... ...#...#..
output:
1
result:
ok single line: '1'
Test #8:
score: 0
Accepted
time: 0ms
memory: 11776kb
input:
20 20 ..#...#...#...#...#. #..#...#...#...#.... ....#...#...#...#..# ..#..#...#...#....#. .#....#...#...#..#.. #...#..#...#....#... ...#....#...#..#...# ..#...#..#....#...#. .#...#....#..#...#.. #...#...#...#...#... ...#...#...#...#...# ..#...#..#....#...#. .#...#....#..#...#.. #...#..#...#....#... ...
output:
0
result:
ok single line: '0'
Test #9:
score: 0
Accepted
time: 3ms
memory: 11816kb
input:
10 16 ..#..#..#..#..#. #..#..#..#..#... .#..#..#..#....# ..#..#..#....#.. #..#..#....#..#. .#..#....#..#..# ..#....#..#..#.. #....#..#..#..#. ...#..#..#..#..# .#..#..#..#..#..
output:
1
result:
ok single line: '1'
Test #10:
score: 0
Accepted
time: 3ms
memory: 11912kb
input:
50 45 ..#...##..##...#...#.#.#.....#..#..##..##.#.. ...#.#.#.#..##...###.#..##.##.#.....#......#. #......#.##.##....#.....#......#.#.#.#...#... .#.#####....##.#.#..###..#.##.###..#...#....# .....#.#.##.#..#..#...#.##...##..#...#....##. .#..#.....##..###...##....##..#...#.##.###... ..#.#.#.#..#.##.#....
output:
0
result:
ok single line: '0'
Test #11:
score: 0
Accepted
time: 3ms
memory: 13872kb
input:
50 45 .....#...#.#..#........#.........#..........# ...##.......#...##...#..#...###.....##...#..# .#...#...#....#....#...#.......#...#..##...#. ......#.......#.#.#.......#..#.#.#....#...... #..#..#.....#.#.......#.#..#..#...#.#....#... .#.#....#.#...#.#...#...#.#....#........#.#.. .....##..#...##.#....
output:
0
result:
ok single line: '0'
Test #12:
score: 0
Accepted
time: 0ms
memory: 11864kb
input:
50 50 .#.......###....#.#..#....#....#...#..##....#.#.#. ............#.................#......##........... ......................................#........... .......................................##......... ...........#...#.................................# #......#.....#..#.........#...............
output:
0
result:
ok single line: '0'
Test #13:
score: 0
Accepted
time: 3ms
memory: 13840kb
input:
50 50 ###...###..#.##..###...#..#...###....#..#.#.##.### #....#.#......#........##......#............##.... .....#..................#........................# ...#.............................................. #................................................# #.........................................
output:
0
result:
ok single line: '0'
Test #14:
score: 0
Accepted
time: 0ms
memory: 15964kb
input:
50 50 ###.####...#.#...###...##.#...###....#..#.#.##.### #...##.#......#........##.....##............##...# ....##..................#...................#..... ...#................#............................. #................................................# #.........................................
output:
0
result:
ok single line: '0'
Test #15:
score: 0
Accepted
time: 0ms
memory: 13900kb
input:
50 50 ###..###...#.##..###...####...###....#..#.#.##.### #....#.#......#........##......#............##.... ....##..................#...................#....# ...#................#............................. #................................................# #.........................................
output:
0
result:
ok single line: '0'
Test #16:
score: 0
Accepted
time: 3ms
memory: 11864kb
input:
50 50 #.#.#.....###..#...#..###.#.....#..###.##.#.#...#. #........###......#....#.......##......##....#.... ........##......#.....#........#.......#.......... .........#...........#................##.......... #..............#.................................# .....#..................#.................
output:
0
result:
ok single line: '0'
Test #17:
score: 0
Accepted
time: 3ms
memory: 11808kb
input:
50 50 #.#.#....####..#...#.####.#.#...#.##.#.##.#.#...#. #........###......#...##.......##......##....#.... ........##......#.....#........#.......#.......... .........#...........#................##.......... #..............#.................................# .....#..................#.................
output:
0
result:
ok single line: '0'
Test #18:
score: 0
Accepted
time: 3ms
memory: 14136kb
input:
50 50 #.#.#....####..#..##.####.#.#...#.##.#.##.#.#...#. #........###......#..###.......##.......#....#.... ........##......#.....#........#.......#.......... .........#...........#................##.......... #..............#.................................# .....#..................#.................
output:
0
result:
ok single line: '0'
Test #19:
score: 0
Accepted
time: 3ms
memory: 14116kb
input:
50 50 .#.###..#...#..#...##.#..##..#....#..#..##..#..#.. .....#......#.....#.#...................#........# #.........#.......#......................#........ ##..............#................................. .....#......................#....................# #.....#...................................
output:
0
result:
ok single line: '0'
Test #20:
score: 0
Accepted
time: 0ms
memory: 13904kb
input:
50 50 ##...#..#..###.#...##.#...#..#....#..#...#.##..#.. .....#....#.#.....#.#...................#........# #.........#.......#......................#........ #...............#................................. #................................................# ##........................................
output:
0
result:
ok single line: '0'
Test #21:
score: 0
Accepted
time: 3ms
memory: 13828kb
input:
50 50 .#.....#.#.#.#..##.#..#.###....##.###.##.###..#.## ..##..#........##....#..#..#...#......#..#.......# #..##.........#..........#..#..###...###..#.....## #.......#...##.#..###..#...#.#..###...#...##.#.... .......#.##....#.##...#...##...#.....#.....##..... #.........##..#.##.#.....#.#....#.........
output:
0
result:
ok single line: '0'
Test #22:
score: 0
Accepted
time: 4ms
memory: 16016kb
input:
50 50 ##.....##...###.##.....##..#..####.#.#..##..#..##. ...#...####..#..###...#.#..#..##...#..#..##...##.. ##..#..#....##..##..#....#...###.....#..###....... .#....#.#....##....##.......#.#.....#....#......## .....#.......#....#........#.....#...#...#.......# .........#..#.#.#..#....#.#..#........#...
output:
0
result:
ok single line: '0'
Test #23:
score: 0
Accepted
time: 0ms
memory: 13988kb
input:
50 50 ##......#...###.##.....##.##...####..##.#...#..##. ...#...##.#..##..##...##........#..#..#..##...##.. ##..##.#.#..###...###....#...###.........##......# ##....#..#....#....#.#..#...#..#..#.....##......#. .....#.#......#...##...#...#..#..#..##...#........ ............#..##..#..#.###..#....#...#...
output:
0
result:
ok single line: '0'
Test #24:
score: 0
Accepted
time: 3ms
memory: 14100kb
input:
50 50 ..#...#...#...#...#...#...#...#...#...#...#...#... ...#...#...#...#...#...#...#...#...#...#...#...#.. .#...#...#...#...#...#...#...#...#...#...#...#...# #...#...#...#...#...#...#...#...#...#...#...#...#. ..#...#...#...#...#...#...#...#...#...#...#...#... ...#...#...#...#...#...#...#...#...#......
output:
0
result:
ok single line: '0'
Test #25:
score: 0
Accepted
time: 0ms
memory: 14104kb
input:
50 50 ..#...#...#...#...#...#...#...#...#...#...#...#... ...#...#...#...#...#...#...#...#...#...#...#...#.. .#...#...#...#...#...#...#...#...#...#...#...#...# #...#...#...#...#...#...#...#...#...#...#...#...#. ..#...#...#...#...#...#...#...#...#...#...#...#... ...#...#...#...#...#...#...#...#...#......
output:
1
result:
ok single line: '1'
Test #26:
score: 0
Accepted
time: 3ms
memory: 14312kb
input:
50 50 ..#...#...#...#...#...#...#...#...#...#...#...#... ...#...#...#...#...#...#...#...#.....#.#...#...#.. .#...#...#...#...#...#...#...#...#...#...#...#...# #.#.....#...#.#.....#...#...#...##..#...#...#...#. ..#...#...#...#...#...#...#...#...#...#...#...#... ...#...#...#...#...#...#...#...#...#......
output:
1
result:
ok single line: '1'
Test #27:
score: 0
Accepted
time: 3ms
memory: 12060kb
input:
50 50 ..#...#...#...#...#...#...#...#...#...#...#...#... .......#...#...#...#...#...#...#...#...#...#...#.. .#...#...#...#...#...#...#...#...#...#...#...#...# #...#...#...#...#...#...#...#...#...#...#...#...#. ..#...#...#...#...#...#...#...#...#...#...#...#... ...#...#...#...#...#...#...#...#...#......
output:
1
result:
ok single line: '1'
Test #28:
score: 0
Accepted
time: 3ms
memory: 12264kb
input:
50 50 ..#...#...#...#...#...#...#...#...#...#...#...#... ...#...#...#...#...#...#...#...#...#...#...#...#.. .#...#...#...#...#...#...#...#...#...#...#...#...# #...#...#...#...#...#...#...#...#...#...#...#...#. ..#...#...#...#...#...#...#...#...#...#...#...#... ...#...#...#...#...#...#...#...#...#......
output:
1
result:
ok single line: '1'
Test #29:
score: 0
Accepted
time: 0ms
memory: 14044kb
input:
50 50 ..#...#...#...#...#...#...#...#...#...#...#...#... ...........#...........#...#...#...#...#...#...#.. .....#...............#...##..#...#...#...#...#...# #...#...............#...#...#...#...#...#.......#. .#..........#.........#.......#...#...#...#.#..... ...........#...#...#...#...#...#...#......
output:
1
result:
ok single line: '1'
Test #30:
score: 0
Accepted
time: 0ms
memory: 14024kb
input:
50 50 ..#...#...#...#...#...#...#...#...#...#...#...#... ...#.....#....#......#.....#...#.....#...#...#.... .#..##.......#...........##..#.....#.#......##.... #.#..##...##.#......#..#.#..#...#...#......#.....# ..#....##...#..#......#.#.....#.#.#..#..#...#...#. ......#....#..#....#..#....#...#.#.#..#...
output:
1
result:
ok single line: '1'
Test #31:
score: 0
Accepted
time: 3ms
memory: 13884kb
input:
50 50 #########################.######################## ########################...####################### #######################.....###################### ######################.......##################### #####################.........#################### ####################...........########...
output:
0
result:
ok single line: '0'
Test #32:
score: 0
Accepted
time: 3ms
memory: 13876kb
input:
50 50 #########################.######################## ########################...####################### #######################.....###################### ######################.......##################### #####################.........#################### ####################...........########...
output:
1
result:
ok single line: '1'
Test #33:
score: 0
Accepted
time: 3ms
memory: 14120kb
input:
50 50 ...........##############.############............ ...........#############...###########............ ...........############.....##########............ ...........###########.......#########............ ...........##########.........########............ ...........#########...........#######....
output:
0
result:
ok single line: '0'
Test #34:
score: 0
Accepted
time: 0ms
memory: 13828kb
input:
50 50 #########################.######################## #######..###############...####################### ######....#############.....###################### #####......###########.......##################### ####........#########.........#################### ###.........########...........########...
output:
0
result:
ok single line: '0'
Test #35:
score: 0
Accepted
time: 3ms
memory: 13972kb
input:
50 50 ..#...#...#...#...#...#...#...#...#...#...#...#... .......#..##.....#.......#....##...#......#......# .#...#...#...#.....#....#....#...#.....#.....#.... #.......#...#......#...#..#..##.......#.....#..... ......##.###........#.#....##.##..#........##....# ....##...#........#.##...##....##....#....
output:
0
result:
ok single line: '0'
Test #36:
score: 0
Accepted
time: 0ms
memory: 11968kb
input:
50 50 ..#...#...#...#...#...#...#...#...#...#...#...#... ...#..##...#.....#...#.#..#...#..............#...# .#...#...###.#.....##....#...#...#...........#.... #.#.....#...#.......##.....#.#.#.........#.....#.. .......#...#.........#....#.#.#.............#...#. ....##...#........#.....#.#....##....#....
output:
1
result:
ok single line: '1'
Test #37:
score: 0
Accepted
time: 3ms
memory: 11864kb
input:
50 50 ..#...#...#...#...#...#...#...#...#...#...#...#... ...#..##...#.....#...#.#..#...#..............#...# .#...#.#....##.....##....#...#...#...........#.... #.#.....#...#........#.....#.#.#.........#........ .......#...#........##....#.#.#.............#..... ....##...#........##....#.#....##....#....
output:
1
result:
ok single line: '1'
Test #38:
score: 0
Accepted
time: 0ms
memory: 12028kb
input:
10 10 ..#...#... .......#.. .........# #.......#. ...#...... .......... .......#.. #......... ..#...#... ...##..#.#
output:
1
result:
ok single line: '1'
Test #39:
score: 0
Accepted
time: 3ms
memory: 13928kb
input:
47 43 #########...#...#####...#...#####...#...### ##########.....#######.....#######.....#### #########.......#####.......#####.......### #########.......#####.......#####.......### ##########...#..######...#..######...#..### ###..#..#..#..#..#..#..#..#..#..#..#..#...# ####...#..######...#..######.....
output:
1
result:
ok single line: '1'
Subtask #2:
score: 70
Accepted
Dependency #1:
100%
Accepted
Test #40:
score: 70
Accepted
time: 59ms
memory: 73596kb
input:
983 991 #########...#...#####...#...#####...#...#####...#...#####...#...#####...#...#####...#...#####...#...#####...#...#####...#...#####...#...#####...#...#####...#...#####...#...#####...#...#####...#...#####...#...#####...#...#####...#...#####...#...#####...#...#####...#...#####...#...#####...#......
output:
1
result:
ok single line: '1'
Test #41:
score: 0
Accepted
time: 12ms
memory: 29372kb
input:
1000 1000 ##################################################################################################################################################################################################################################################################################################...
output:
1
result:
ok single line: '1'
Test #42:
score: 0
Accepted
time: 15ms
memory: 31312kb
input:
1000 1000 ##################################################################################################################################################################################################################################################################################################...
output:
0
result:
ok single line: '0'
Test #43:
score: 0
Accepted
time: 88ms
memory: 124536kb
input:
998 998 ...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...
output:
1
result:
ok single line: '1'
Test #44:
score: 0
Accepted
time: 102ms
memory: 124064kb
input:
998 998 #..#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...
output:
0
result:
ok single line: '0'
Test #45:
score: 0
Accepted
time: 80ms
memory: 123836kb
input:
998 998 ...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...
output:
1
result:
ok single line: '1'
Test #46:
score: 0
Accepted
time: 91ms
memory: 124180kb
input:
998 998 ...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...#...
output:
1
result:
ok single line: '1'
Test #47:
score: 0
Accepted
time: 16ms
memory: 32460kb
input:
1000 1000 .....................................................................................................................................................................................................................................................................................................
output:
0
result:
ok single line: '0'
Test #48:
score: 0
Accepted
time: 28ms
memory: 34728kb
input:
1000 1000 .............................................................................................................................................................................#............................................................#..................#.......................................
output:
0
result:
ok single line: '0'
Test #49:
score: 0
Accepted
time: 50ms
memory: 55472kb
input:
1000 1000 .....#....#............................#...................#.###.........#.......#.#..#.......#................#.#............................#...#..............#.#........#.....#..........#.##.....#....#.......#.#...................##.........##...#.##.................#......#........#......
output:
0
result:
ok single line: '0'
Test #50:
score: 0
Accepted
time: 128ms
memory: 97620kb
input:
1000 1000 #.########......#.#....#...#..#...#.#............#..#..#.##.#.##.##...#..#...#..###....##.##.####....#....#.#.###....##.###.###...#.....#..##..##..#.#..#.###.###.#.#.....#.##........#...#.#...#.#.######.#...#.#.#..##.##.##........#.##..##...##.#####...#.####.#..#.#.##.....#....##....#.##.#...
output:
0
result:
ok single line: '0'