QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#335611#4079. 칠하기socpite0 0ms0kbC++202.4kb2024-02-23 17:07:452024-02-23 17:07:45

Judging History

你现在查看的是最新测评结果

  • [2024-02-23 17:07:45]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-02-23 17:07:45]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

const int maxn = 1e3+5;
int LR[maxn][maxn], UD[maxn][maxn];
int vis[maxn*maxn*2], scc[maxn*maxn*2], d[maxn*maxn*2];

vector<int> g[maxn*maxn*2];
vector<int> rg[maxn*maxn*2];
vector<int> cg[maxn*maxn*2];

vector<int> ord;
int scnt = 0;
int cnt = 0;

void dfs(int x){
    vis[x] = 1;
    for(auto v: g[x]){
        if(vis[v])continue;
        dfs(v);
    }
    ord.push_back(x);
}

void dfs2(int x){
    scc[x] = scnt;
    for(auto v: rg[x]){
        if(scc[v])continue;
        dfs2(v);
    }
}

int solve() {
    for(int i = 1; i <= cnt; i++){
        if(!vis[i])dfs(i);
        for(auto v: g[i])rg[v].push_back(i);
    }
    reverse(ord.begin(), ord.end());
    for(auto v: ord){
        if(scc[v])continue;
        scnt++;
        dfs2(v);
    }
    for(int i = 1; i <= cnt; i++){
        for(auto v: g[i]){
            if(scc[i] == scc[v])continue;
            cg[scc[i]].push_back(scc[v]);
            d[scc[v]]++;
        }
    }
    queue<int> q;
    for(int i = 1; i <= scnt; i++){
        if(!d[i])q.push(i);
    }
    vector<int> topo_ord;
    while(!q.empty()){
        auto x = q.front();
        topo_ord.push_back(x);
        for(auto v: cg[x]){
            d[v]--;
            if(!d[v])q.push(v);
        }
    }
    for(int i = 0; i + 1 < topo_ord.size(); i++){
        bool chk = 0;
        for(auto v: cg[topo_ord[i]])if(v == topo_ord[i+1])chk = 1;
        if(!chk)return 0;
    }
    return 1;
}

int yellowblue(int N, int M, vector<string> V){
    int prv = -1;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < M; j++){
            if(V[i][j] == '#')prv = -1;
            else {
                if(prv == -1)prv = ++cnt;
                LR[i][j] = prv;
            }
        }
        prv = -1;
    }
    prv = -1;
    for(int i = 0; i < M; i++){
        for(int j = 0; j < N; j++){
            if(V[j][i] == '#')prv = -1;
            else {
                if(prv == -1)prv = ++cnt;
                UD[j][i] = prv;
            }
        }
        prv = -1;
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < M; j++){
            if(V[i][j] == '#')continue;
            if(i == 0 || V[i-1][j] == '#' || i == N-1 || V[i+1][j] == '#')g[UD[i][j]].push_back(LR[i][j]);
            if(j == 0 || V[i][j-1] == '#' || j == M-1 || V[i][j+1] == '#')g[LR[i][j]].push_back(UD[i][j]);
        }
    }
    return solve();
}

详细

Subtask #1:

score: 0
Time Limit Exceeded

Test #1:

score: 0
Time Limit Exceeded

input:

3 5
...##
....#
#.#..

output:

Unauthorized output

result:


Subtask #2:

score: 0
Skipped

Dependency #1:

0%