QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#662114 | #9431. The Quest for El Dorado | sevenki | WA | 65ms | 46040kb | C++17 | 2.8kb | 2024-10-20 21:05:17 | 2024-10-20 21:05:17 |
Judging History
answer
#include <bits/stdc++.h>
#define mkp make_pair
#define fi first
#define se second
#define debug(x) cerr<<"line: "<<__LINE__<<" with "<<x<<"\n"
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using vi = vector<int>;
const int mod = 998244353;
const int INF = 0x3f3f3f3f;
template<class T>bool chkMin(T &x,T y){if(x>y)return x=y,true;return false;}
template<class T>bool chkMax(T &x,T y){if(x<y)return x=y,true;return false;}
template<class T>void moder(T &x){x%=mod;}
const int MAXN = 500005;
int n,m,k;
struct edge{int v,c,w;};
vector<edge> vec[MAXN];
int logn[MAXN];
struct RMQ{
vector<array<int,20>> st;
vector<int> pos;
void add(int p,int len){
st.push_back({0});
st[(int)st.size()-1][0]=len;
pos.push_back(p);
}
void init(){
int n=(int)pos.size()-1;
for(int j=1;j<20;j++){
for(int i=0;i+(1<<j)-1<n;i++){
st[i][j]=max(st[i][j-1],st[i+(1<<(j-1))][j-1]);
}
}
}
int query(int l,int r){
int LG = logn[r-l+1];
return max(st[l][LG],st[r-(1<<LG)+1][LG]);
}
int getNext(int p,int len){
int L = upper_bound(pos.begin(),pos.end(),p)-pos.begin();
if(L==(int)pos.size())return -1;
int R = (int)pos.size()-1;
int lb = L;
if(query(L,R)<len)return -1;
auto check = [&](int x){
return query(lb,x)>=len;
};
while(L<R){
int mid = (L+R)/2;
if(check(mid))R=mid;
else L=mid+1;
}
return pos[L];
}
}rmq[MAXN];
struct node{int bel,len;}a[MAXN];
bool vis[MAXN];
pii dis[MAXN];
void solve(){
cin>>n>>m>>k;
for(int i=1;i<=n;i++)vec[i].clear();
for(int i=1;i<=m;i++){
int u,v,c,w;cin>>u>>v>>c>>w;
vec[u].push_back({v,c,w});
vec[v].push_back({u,c,w});
rmq[i].st.clear();
rmq[i].pos.clear();
}
for(int i=1;i<=k;i++){
int bel,len;cin>>bel>>len;
rmq[bel].add(i,len);
a[i]={bel,len};
}
for(int i=1;i<=n;i++)dis[i]={INF,INF},vis[i]=0;
dis[1]={1,0};
using inq = pair<pii,int>;
priority_queue<inq,vector<inq>,greater<inq>> q;
q.push({dis[1],1});
while(!q.empty()){
int k = q.top().second;q.pop();
if(vis[k])continue;
vis[k]=1;
for(auto [j,c,w] : vec[k]){
if(a[dis[k].first].bel == c
&& a[dis[k].first].len>=dis[k].second+w){
if(dis[j]>pii(dis[k].first,dis[k].second+w)){
dis[j]=pii(dis[k].first,dis[k].second+w);
q.push({dis[j],j});
}
}else{
//find a new one
int nxt = rmq[c].getNext(dis[k].first,w);
if(nxt==-1)continue;
if(dis[j]>pii(nxt,w)){
dis[j]=pii(nxt,w);
q.push({dis[j],j});
}
}
}
}
for(int i=1;i<=n;i++)cout<<vis[i];
cout<<"\n";
}
signed main() {
//cerr<<(&s1-&s2)/1024.0/1024<<" ";
cin.tie(nullptr)->sync_with_stdio(false);
for(int i=2;i<=n;i++)logn[i]=logn[i/2]+1;
int T;cin>>T;
while(T--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 44068kb
input:
2 5 6 4 1 2 1 30 2 3 1 50 2 5 5 50 3 4 6 10 2 4 5 30 2 5 1 40 1 70 6 100 5 40 1 30 3 1 1 2 3 1 10 1 100
output:
11011 100
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 65ms
memory: 46040kb
input:
1110 46 80 30 44 23 5 46 10 28 1 64 32 34 3 40 9 36 1 26 15 14 5 95 38 19 2 34 2 17 4 183 10 38 2 81 5 15 2 83 31 38 3 100 40 30 1 53 41 10 1 193 29 20 5 18 14 41 3 78 8 16 5 74 46 13 3 78 44 28 3 45 1 40 3 133 5 32 1 108 22 26 2 83 10 38 1 77 11 40 1 11 17 21 2 66 41 46 3 98 9 36 2 25 40 18 1 19 27...
output:
1000000000000100000010000000000100000100000000 1000000010000001011010000000001000000000000000 1000000000000000000000000000000000000000000000 1001000000000000000000000010000000000000000000 1000000000000000000000000000000000000000000000 1001100010000000100000100000000001001010010 100000000000000000000...
result:
wrong answer 1st lines differ - expected: '1000110011110111110010100001010100100101000000', found: '1000000000000100000010000000000100000100000000'