QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#789852 | #9810. Obliviate, Then Reincarnate | Cai_Guang | WA | 0ms | 3564kb | C++20 | 1.4kb | 2024-11-27 22:16:31 | 2024-11-27 22:16:31 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int inf=1e18;
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int n,m,q;
cin>>n>>m>>q;
vector<int>vis(n,-inf),res(n,-1ll);
vector<vector<array<int,2>>>e(n);
auto get=[&](int x)->int{
return ((x%n)+n)%n;
};
for(int i=0;i<m;++i){
int x,y;
cin>>x>>y;
if(!y) continue;
e[get(x)].push_back({x,y});
if(y%n==0) res[get(x)]=1;
}
for(int i=0;i<n;++i){
if(res[i]!=-1) continue;
stack<int>st;
auto dfs=[&](auto dfs,int u)->int{
int du=get(u);
st.push(du);
if(res[du]!=-1){
return res[du];
}
if(vis[du]!=-inf){
if(vis[du]==u) return -1;
else return res[du]=1;
}
vis[du]=u;
int b=-1;
for(auto [x,y]:e[du]){
if(dfs(dfs,u+y)==1) b=1;
}
vis[du]=-inf;
return res[du]=b;
};
while(!st.empty()){
auto u=st.top();
st.pop();
if(res[u]==-1) res[u]=0;
}
res[i]=dfs(dfs,i);
}
for(int i=0;i<q;++i){
int x;
cin>>x;
cout<<(res[get(x)]?"Yes\n":"No\n");
}
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3564kb
input:
3 2 3 1 1 -1 3 1 2 3
output:
Yes Yes Yes
result:
wrong answer 3rd words differ - expected: 'No', found: 'Yes'