結果

問題 No.1014 competitive fighting
ユーザー snow39snow39
提出日時 2020-03-21 12:42:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,195 bytes
コンパイル時間 2,359 ms
コンパイル使用メモリ 117,992 KB
実行使用メモリ 71,504 KB
最終ジャッジ日時 2023-08-23 11:33:25
合計ジャッジ時間 12,072 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,508 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 114 ms
46,396 KB
testcase_11 AC 157 ms
71,504 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 12 ms
7,008 KB
testcase_34 AC 137 ms
52,620 KB
testcase_35 AC 189 ms
63,180 KB
testcase_36 AC 126 ms
48,264 KB
testcase_37 AC 6 ms
4,876 KB
testcase_38 AC 112 ms
43,232 KB
testcase_39 AC 57 ms
22,380 KB
testcase_40 AC 108 ms
43,536 KB
testcase_41 AC 74 ms
31,408 KB
testcase_42 AC 176 ms
66,796 KB
testcase_43 AC 11 ms
6,548 KB
testcase_44 AC 159 ms
60,780 KB
testcase_45 AC 94 ms
34,224 KB
testcase_46 AC 17 ms
9,152 KB
testcase_47 AC 53 ms
22,120 KB
testcase_48 AC 132 ms
45,908 KB
testcase_49 AC 6 ms
5,092 KB
testcase_50 AC 165 ms
63,764 KB
testcase_51 AC 92 ms
38,640 KB
testcase_52 AC 7 ms
5,248 KB
testcase_53 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0