QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#335608#4079. 칠하기tuanlinh1230 1ms3816kbC++202.8kb2024-02-23 17:05:042024-02-23 17:05:04

Judging History

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

  • [2024-02-23 17:05:04]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3816kb
  • [2024-02-23 17:05:04]
  • 提交

answer

#include<bits/stdc++.h>
#define ll int
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ld long double
using namespace std;

ll yellowblue(ll n, ll m, vector <string> V)
{
    ll crr=0;
    vector <pair<pll, pll>> ver, hor;
    vector <vector <ll>> v(n, vector <ll> (m)), h(n, vector <ll> (m));
    for (ll i=0; i<n; i++)
    {
        auto connect=[&](ll l, ll r)
        {
            hor.pb({{crr, i}, {l, r}});
            for (ll j=l; j<=r; j++)
                h[i][j]=crr; crr++;
        };
        for (ll j=0, lst=-1; j<m; j++)
        {
            if (V[i][j]=='#')
            {
                if (lst==-1) continue;
                connect(lst, j-1), lst=-1;
            }
            else if (lst==-1) lst=j;
            if (j==m-1 && lst!=-1) connect(lst, j);
        }
    }
    for (ll i=0; i<m; i++)
    {
        auto connect=[&](ll l, ll r)
        {
            ver.pb({{crr, i}, {l, r}});
            for (ll j=l; j<=r; j++)
                v[j][i]=crr; crr++;
        };
        for (ll j=0, lst=-1; j<n; j++)
        {
            if (V[j][i]=='#')
            {
                if (lst==-1) continue;
                connect(lst, j-1), lst=-1;
            }
            else if (lst==-1) lst=j;
            if (j==n-1 && lst!=-1) connect(lst, j);
        }
    }
    vector <vector <ll>> A(crr);
    for (pair<pll, pll> s:hor)
    {
        ll c=s.fi.fi, i=s.fi.se, l=s.se.fi, r=s.se.se;
        A[c].pb(v[i][l]), A[c].pb(v[i][r]);
    }
    for (pair<pll, pll> s:ver)
    {
        ll c=s.fi.fi, i=s.fi.se, l=s.se.fi, r=s.se.se;
        A[c].pb(h[l][i]), A[c].pb(h[r][i]);
    }
    vector <ll> cmp(crr), lo(crr, 0), num(crr, 0);
    ll Time=0, cnt=0;
    stack <ll> st;
    function<void(ll)> dfs=[&](ll u)
    {
        st.push(u);
        lo[u]=num[u]=++Time;
        for (ll v:A[u])
        {
            if (!num[v]) dfs(v), lo[u]=min(lo[u], lo[v]);
            else lo[u]=min(lo[u], num[v]);
        }
        if (lo[u]==num[u])
        {
            while (st.top()!=u)
                cmp[st.top()]=cnt, st.pop();
            cmp[st.top()]=cnt, st.pop(), cnt++;
        }
    };
    for (ll i=0; i<crr; i++)
        if (!num[i]) dfs(i);
    vector <ll> deg(cnt, 0);
    vector <vector <ll>> B(cnt);
    map <pll, bool> Map;
    for (ll i=0; i<crr; i++)
        for (ll j:A[i]) 
            if (cmp[i]!=cmp[j])
                Map[{cmp[i], cmp[j]}]=1, B[cmp[j]].pb(cmp[i]), deg[cmp[i]]++;
    vector <ll> q;
    for (ll i=0; i<cnt; i++)
        if (!deg[i]) q.pb(i);
    for (ll i=0; i<q.size(); i++)
    {
        if (i && !Map[{q[i], q[i-1]}]) return 0;
        for (ll v:B[q[i]])
        {
            deg[v]--;
            if (!deg[v]) q.pb(v);
        }
    }
    return 1;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 30
Accepted
time: 1ms
memory: 3528kb

input:

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

output:

1

result:

ok single line: '1'

Test #2:

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

input:

4 4
..#.
#...
...#
.#..

output:

1

result:

ok single line: '1'

Test #3:

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

input:

15 15
#######..######
######....#####
#####......####
####........###
###..........##
##............#
#..............
...............
#.............#
##...........##
###.........###
####.......####
#####.....#####
######...######
#######.#######

output:

1

result:

ok single line: '1'

Test #4:

score: -30
Wrong Answer
time: 0ms
memory: 3500kb

input:

16 16
########..######
#######....#####
######......####
#####........###
####..........##
###............#
##..............
................
##.............#
###...........##
####.........###
#####.......####
######.....#####
#######...######
########.#######
########.#######

output:

1

result:

wrong answer 1st lines differ - expected: '0', found: '1'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%