結果
| 問題 |
No.1014 competitive fighting
|
| コンテスト | |
| ユーザー |
snow39
|
| 提出日時 | 2020-03-21 12:42:20 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,195 bytes |
| コンパイル時間 | 1,692 ms |
| コンパイル使用メモリ | 120,048 KB |
| 実行使用メモリ | 71,440 KB |
| 最終ジャッジ日時 | 2024-12-21 14:05:55 |
| 合計ジャッジ時間 | 12,153 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 WA * 27 |
ソースコード
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}
/* example
int n=scc.scc();
scc.build(n,g);
(g:outside)
*/
struct StronglyConnectedComponents{
vector<int> used,cmp,vs;
vector<vector<int>> ori;
vector<vector<int>> v,rv;
StronglyConnectedComponents(int n):used(n),cmp(n,-1),v(n),rv(n){}
void add_edge(int x,int y){
v[x].push_back(y);
rv[y].push_back(x);
}
void dfs(int x){
used[x]=true;
for(auto to:v[x]) if(!used[to]) dfs(to);
vs.push_back(x);
}
void rdfs(int x,int k){
cmp[x]=k;
for(auto to:rv[x]) if(cmp[to]==-1) rdfs(to,k);
}
int scc(){
for(int i=0;i<used.size();i++) if(!used[i]) dfs(i);
reverse(vs.begin(),vs.end());
int k=0;
for(auto x:vs) if(cmp[x]==-1) rdfs(x,k++);
ori.resize(k);
for(int i=0;i<used.size();i++) ori[cmp[i]].push_back(i);
return k;//k:size
}
void build(int k,vector<vector<int>> &g){
g.resize(k);
for(int i=0;i<v.size();i++){
for(auto to:v[i]){
int x=cmp[i],y=cmp[to];
if(x!=y) g[x].push_back(y);
}
}
}
};
int N;
vector<vector<int>> g;
vector<ll> A,B,C;
vector<ll> V;
vector<ll> dp;
const ll INF=1e18;
vector<vector<int>> ori;
void dfs(int now,int par){
if(dp[now]!=0) return;
ll res=0;
for(auto nex:g[now]){
if(nex==par) continue;
dfs(nex,now);
if(dp[nex]==-INF){
dp[now]=-INF;
return;
}
chmax(res,dp[nex]);
}
dp[now]=V[now]+res;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
cin>>N;
A.resize(N);
B.resize(N);
C.resize(N);
rep(i,N) cin>>A[i]>>B[i]>>C[i];
vector<int> ord(N);
rep(i,N) ord[i]=i;
sort(ord.begin(),ord.end(),[&](int a,int b){
return A[a]<A[b];
});
vector<ll> w=A;
sort(w.begin(),w.end());
g.resize(2*N);
for(int i=0;i<N;i++){
int now=ord[i];
ll lim=B[now]-C[now];
int z=upper_bound(w.begin(),w.end(),lim)-w.begin();
if(z>0) g[now].push_back(N+z-1);
}
for(int i=N;i<2*N;i++){
if(i+1<2*N) g[i+1].push_back(i);
g[i].push_back(ord[i-N]);
}
StronglyConnectedComponents scc(2*N);
for(int i=0;i<2*N;i++){
for(auto to:g[i]) scc.add_edge(i,to);
}
int M=scc.scc();
g.clear();
scc.build(M,g);
ori=scc.ori;
vector<int> num(M,0);
rep(i,N) num[scc.cmp[i]]++;
V.resize(M,0);
dp.resize(M,0);
for(int i=0;i<M;i++) for(auto p:ori[i]) if(p<N) V[i]+=B[p];
for(int i=0;i<M;i++) if(num[scc.cmp[i]]>1){
V[i]=-INF;
dp[i]=-INF;
}
rep(i,M) if(dp[i]==0) dfs(i,-1);
vector<ll> ans(N,0);
rep(i,M) for(auto p:ori[i]) if(p<N) ans[p]=dp[i];
rep(i,N){
if(ans[i]==-INF) cout<<"BAN"<<"\n";
else cout<<ans[i]<<"\n";
}
return 0;
}
snow39