QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#175115 | #4162. 所驼门王的宝藏 | chenqingborui | 20 | 172ms | 126712kb | C++20 | 3.6kb | 2023-09-10 16:12:20 | 2023-09-10 16:12:20 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define N 1001001
using namespace std;
int n,r,c,h[N],w[N],bl[N],cnt[N],dp[N],dfnid,dfn[N],low[N],vis[N],id,in[N],ans;
int dx[]={-1,-1,-1,0,0,1,1,1},dy[]={-1,0,1,-1,1,-1,0,1};
map<pair<int,int>,int>mp;
vector<int>g[N],e[N],hh[N],ww[N];
queue<int>q;
stack<int>st;
struct node
{
int x,y,t;
bool operator < (const node &s ) const
{
return t<s.t;
}
}a[N];
void dfs(int u)
{
dfnid++;
dfn[u]=dfnid;
low[u]=dfnid;
st.push(u);
vis[u]=1;
for(int i=0;i<g[u].size();i++)
{
int v=g[u][i];
if(dfn[v]==0)
{
dfs(v);
low[u]=min(low[u],low[v]);
}
else if(vis[v]==1)
low[u]=min(low[u],low[v]);
}
if(dfn[u]==low[u])
{
id++;
while(1)
{
int v=st.top();
st.pop();
cnt[id]++;
vis[v]=0;
bl[v]=id;
if(v==u)
break;
}
}
}
signed main()
{
cin>>n>>r>>c;
for(int i=1;i<=n;i++)
{
cin>>a[i].x>>a[i].y>>a[i].t;
if(a[i].t==1)
a[i].t=2;
else if(a[i].t==2)
a[i].t=1;
}
sort(a+1,a+n+1);
for(int i=1;i<=n;i++)
{
if(a[i].t!=1)
hh[a[i].y].push_back(i);
if(a[i].t!=2)
ww[a[i].x].push_back(i);
}
for(int i=1;i<=n;i++)
{
mp[{a[i].x,a[i].y}]=i;
if(a[i].t==1)
{
if(h[a[i].y]==0)
{
h[a[i].y]=i;
for(int j=0;j<hh[a[i].y].size();j++)
{
int v=hh[a[i].y][j];
g[i].push_back(v);
}
}
else
{
g[i].push_back(h[a[i].y]);
g[h[a[i].y]].push_back(i);
}
}
else if(a[i].t==2)
{
if(w[a[i].x]==0)
{
w[a[i].x]=i;
for(int j=0;j<ww[a[i].x].size();j++)
{
int v=ww[a[i].x][j];
g[i].push_back(v);
}
}
else
{
g[i].push_back(w[a[i].x]);
g[w[a[i].x]].push_back(i);
}
}
else
{
for(int j=0;j<8;j++)
{
int tx=a[i].x+dx[j],ty=a[i].y+dy[j];
if(mp.find({tx,ty})!=mp.end())
g[i].push_back(mp[{tx,ty}]);
}
}
}
for(int i=1;i<=n;i++)
if(dfn[i]==0)
dfs(i);
for(int i=1;i<=n;i++)
for(int j=0;j<g[i].size();j++)
{
int v=g[i][j];
if(bl[i]!=bl[v])
{
e[bl[i]].push_back(bl[v]);
in[bl[v]]++;
}
}
for(int i=1;i<=id;i++)
if(in[i]==0)
{
dp[i]=cnt[i];
ans=max(ans,dp[i]);
q.push(i);
}
while(!q.empty())
{
int u=q.front();
q.pop();
for(int i=0;i<e[u].size();i++)
{
int v=e[u][i];
dp[v]=max(dp[v],dp[u]);
in[v]--;
if(in[v]==0)
{
dp[v]+=cnt[v];
ans=max(ans,dp[v]);
q.push(v);
}
}
}
cout<<ans;
return 0;
}
/*
10 7 7
2 2 2
2 4 2
1 7 2
2 7 2
4 2 2
4 4 2
6 7 2
7 7 2
7 5 2
5 2 2
*/
详细
Test #1:
score: 10
Accepted
time: 8ms
memory: 105980kb
input:
16 20 20 5 6 2 16 6 2 11 6 3 12 7 1 12 12 2 4 6 1 1 12 2 2 12 3 4 10 1 3 12 1 3 2 3 10 12 3 4 12 3 16 12 3 3 1 1 3 14 1
output:
12
result:
ok single line: '12'
Test #2:
score: 0
Wrong Answer
time: 12ms
memory: 108100kb
input:
300 1000 1000 961 867 3 961 868 1 961 189 1 961 68 3 961 140 2 29 140 1 961 218 3 961 217 1 961 3 1 70 140 1 961 135 2 961 7 3 103 135 3 29 33 1 163 140 1 960 868 2 961 181 1 247 140 1 961 69 2 247 215 3 29 213 3 29 55 1 163 290 3 131 140 1 29 186 3 70 75 3 961 133 1 29 68 3 163 22 1 29 279 3 960 6 ...
output:
169
result:
wrong answer 1st lines differ - expected: '186', found: '169'
Test #3:
score: 0
Wrong Answer
time: 8ms
memory: 106076kb
input:
500 100000 100000 15043 25566 3 15044 25566 1 15042 25567 3 15043 25565 2 15042 25566 3 15043 25568 2 15042 25568 3 15041 25565 1 15044 104 2 168 25565 3 15044 491 1 15044 81 3 168 25564 1 235 104 3 15042 25565 1 15041 25566 2 15044 469 3 15044 25567 1 15044 330 1 175 25566 3 146 104 3 15043 25567 3...
output:
250
result:
wrong answer 1st lines differ - expected: '275', found: '250'
Test #4:
score: 0
Wrong Answer
time: 16ms
memory: 108780kb
input:
2500 5000 5000 3360 701 3 3361 700 3 3359 701 3 3359 700 3 3360 700 1 3361 699 2 3358 701 1 3358 700 3 3358 699 1 2447 699 2 3358 1086 3 3358 1615 1 3362 700 1 3362 1465 1 3362 1798 2 3362 699 3 3357 1087 3 3362 1261 3 3360 702 3 3361 701 2 3359 703 3 499 699 2 3358 702 3 3358 1087 3 3361 698 3 210 ...
output:
1279
result:
wrong answer 1st lines differ - expected: '1346', found: '1279'
Test #5:
score: 0
Wrong Answer
time: 88ms
memory: 116520kb
input:
50000 5000 5000 3607 4830 3 4313 4830 1 4626 4830 3 1386 4830 3 4641 4830 1 1512 4830 3 402 4830 2 2934 4830 2 401 4831 1 4626 4584 1 4386 4831 3 4641 2551 1 3557 4830 1 2491 4830 3 2334 4584 3 3556 4831 3 4387 4831 3 3607 3496 3 4626 4601 3 4626 2217 3 3556 4830 3 3556 4786 3 4364 3496 3 402 1201 2...
output:
9730
result:
wrong answer 1st lines differ - expected: '10397', found: '9730'
Test #6:
score: 0
Wrong Answer
time: 86ms
memory: 120772kb
input:
50000 1000000 1000000 20363 13775 3 10221 13775 3 10221 13969 3 10221 29039 3 10221 27851 3 654 13775 3 10649 29039 3 10221 22361 3 10649 8092 3 10648 8092 3 10649 24920 3 10221 25255 3 10220 25254 3 10221 17082 3 10222 13968 3 32129 27851 3 10221 23924 3 4819 29039 3 10222 13776 3 654 27930 3 10220...
output:
2994
result:
wrong answer 1st lines differ - expected: '3256', found: '2994'
Test #7:
score: 0
Wrong Answer
time: 124ms
memory: 126312kb
input:
80000 1000000 1000000 29977 11241 3 29977 15584 3 29977 375 3 29977 3093 3 29977 31245 2 25192 15584 3 29978 31246 1 29977 23943 2 29431 31245 3 25192 2098 3 29976 374 1 7181 375 3 29977 22345 3 29979 31246 3 5598 31245 3 29977 17843 3 29431 31246 2 29976 31244 3 17885 374 3 29976 31061 3 29977 3124...
output:
17072
result:
wrong answer 1st lines differ - expected: '18588', found: '17072'
Test #8:
score: 10
Accepted
time: 117ms
memory: 126596kb
input:
100000 1000000 1000000 19362 10998 2 17887 10998 2 17887 691 2 17887 18793 2 19362 22537 1 17887 18792 1 19362 23192 2 19362 9406 2 19362 10999 1 17887 21103 1 19362 2323 2 17887 1781 2 19362 12326 1 7225 23192 1 8952 1781 1 17887 8534 1 19362 2725 2 17887 6665 1 17887 14381 1 19362 26932 1 22259 18...
output:
77333
result:
ok single line: '77333'
Test #9:
score: 0
Wrong Answer
time: 166ms
memory: 126504kb
input:
100000 1000000 1000000 14954 14897 3 14954 23720 2 28995 14897 2 26335 14897 3 26334 14897 2 21984 14897 3 26334 13037 3 14955 14896 3 26333 13037 2 26334 31550 2 26333 14897 3 26335 18761 3 26333 14369 3 26333 16092 3 28994 14898 3 26334 18762 3 21983 14898 3 26333 31709 1 26335 14898 3 14954 8301 ...
output:
24101
result:
wrong answer 1st lines differ - expected: '26001', found: '24101'
Test #10:
score: 0
Wrong Answer
time: 172ms
memory: 126712kb
input:
100000 1000000 1000000 10588 4708 3 10588 28735 3 10588 28736 3 10587 4709 3 10588 20418 3 10586 4709 3 10586 17297 2 10586 26967 3 10587 17296 3 7718 17297 3 7576 17296 3 7718 3553 3 25009 17296 3 25008 17297 3 7719 3552 2 10587 14985 3 10586 24976 3 10588 16895 2 10588 11593 1 10587 14986 3 6611 3...
output:
13315
result:
wrong answer 1st lines differ - expected: '15763', found: '13315'