QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#515588 | #3805. Promotions | Bacily# | WA | 3ms | 4244kb | C++20 | 1.9kb | 2024-08-11 18:57:01 | 2024-08-11 18:57:01 |
Judging History
answer
#include <bits/stdc++.h>
#define lll __int128
#define el '\n'
#define sz(x) x.size()
using namespace std;
using ll = long long;
using ull = unsigned long long;
vector<vector<int>>adj;
vector<int>lvl;
int mx;
void bfs(queue<int>&q){
while(!q.empty()){
int node=q.front();
q.pop();
for(auto child : adj[node]){
if(lvl[child]==-1){
lvl[child]=lvl[node]+1;
mx=max(mx,lvl[child]);
q.push(child);
}
}
}
}
void tc() {
int l,r,n,m;cin>>l>>r>>n>>m;
adj=vector<vector<int>>(n);
vector<int>num(n);
lvl=vector<int>(n,-1);
for(int i=0;i<m;i++){
int u,v;cin>>u>>v;
adj[u].push_back(v);
num[v]++;
}
queue<int>q;
for(int i=0;i<n;i++){
if(!num[i])lvl[i]=0,q.push(i);
}
bfs(q);
vector<int>freq(mx+1);
for(int i=0;i<n;i++)freq[lvl[i]]++;
int sum=0,ans=0,ans_a=n,ans_b=n;
for(int i=0;i<=mx;i++){
if(sum+freq[i]<=l)sum+=freq[i];
else{
l-=sum;
l-=((freq[i]+1)/2);
if(l>0){
ans_a=sum+l;
if(freq[i]%2==1)ans_a++;
}
else ans_a=sum;
break;
}
}
sum=0;
for(int i=0;i<=mx;i++){
if(sum+freq[i]<=r)sum+=freq[i];
else{
r-=sum;
if(r-((freq[i]+1)/2)>0){
r-=((freq[i]+1)/2);
ans_b=sum+r;
ans=n-sum-freq[i];
if(freq[i]%2==1)ans_b++;
}
else ans=n-sum-2*r,ans_b=sum;
break;
}
}
cout<<ans_a<<el<<ans_b<<el<<ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//int t;cin >> t;
//while (t--)
tc();
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3656kb
input:
3 4 7 8 0 4 1 2 1 5 5 2 6 4 0 1 2 3 4 5
output:
2 4 3
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 3ms
memory: 4244kb
input:
3000 3500 5000 20000 1756 555 4733 3690 2912 2765 1233 1405 2822 1013 1664 4643 465 3265 3133 3063 2592 2060 2540 3030 209 2208 2708 3115 4839 463 9 3672 3446 2864 198 3985 1947 3892 1312 4255 130 485 3183 3653 1081 72 1730 3727 1017 1731 2494 4156 4826 2405 984 3653 4649 3164 929 4453 4163 4336 80 ...
output:
1584 2084 1369
result:
wrong answer 1st lines differ - expected: '1', found: '1584'