QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#698302 | #6692. Building Company | huzhaoxin | RE | 0ms | 3528kb | C++23 | 1.8kb | 2024-11-01 18:44:07 | 2024-11-01 18:44:08 |
Judging History
answer
/*
*****************************
* 作者:huzhaoxin *
* 努力加油,努力赚钱娶媳妇回家 *
* 时时刻刻爱老婆 *
*****************************
*/
#include<bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
const double eps = 1e-9;
const long long mod = 1e9 + 7;
const long long inf = 2e12 + 7;
/*---------------------------------------------------------------------------*/
void solve() {
ll n;
cin>>n;
map<ll,ll>mp;
for(int i=1;i<=n;i++){
ll a,b;
cin>>a>>b;
mp[a]+=b;
}
cin>>n;
vector<ll>cnt(n+1);
set<pll>st[n+1];
vector<vector<ll>>v(n+1);
for(int i=1;i<=n;i++){
ll m;
cin>>m;
for(int j=1;j<=m;j++){
ll a,b;
cin>>a>>b;
if(mp[a]>=b)continue;
else{
cnt[i]++;
st[a].insert({b,(ll)i});
// cout<<a<<"--"<<b<<" "<<i<<endl;
}
}
ll k;
cin>>k;
for(int j=1;j<=k;j++){
ll a,b;
cin>>a>>b;
v[i].push_back(a);
v[i].push_back(b);
}
}
queue<ll>q;
ll res=0;
for(int i=1;i<=n;i++){
if(cnt[i]==0){
q.push(i);
}
}
while(q.size()){
ll tmp=q.front();
q.pop();
res++;
for(int i=0;i<v[tmp].size();i+=2){
ll a=v[tmp][i];
ll b=v[tmp][i+1];
// cout<<"<<"<<a<<" "<<b<<endl;
ll now=mp[a]+b;
mp[a]+=b;
while(st[a].size()){
auto it=*st[a].begin();
// cout<<it.first<<" "<<it.second<<endl;
if(it.first>now)break;
st[a].erase(st[a].begin());
cnt[it.second]--;
if(cnt[it.second]==0)q.push(it.second);
}
}
}
cout<<res<<endl;
}
/*---------------------------------------------------------------------------*/
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll T;
// for (cin >> T; T; T--)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3528kb
input:
2 2 1 1 2 5 1 3 1 0 2 1 1 2 1 2 3 2 2 1 3 1 5 2 3 3 4 1 2 5 3 2 1 1 1 3 4 1 1 3 0 1 3 2
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: -100
Runtime Error
input:
3 610031727 590328742 816793299 18485566 654221125 47823436 10 3 610031727 224714165 816793299 491951703 654221125 593479446 1 610031727 538596643 1 610031727 551036304 3 816793299 262985484 610031727 52580932 654221125 424397787 1 654221125 889197190 3 654221125 126924193 610031727 963399336 816793...