結果
| 問題 | 
                            No.2100 [Cherry Alpha C] Two-way Steps
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2022-10-14 23:38:00 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 3,777 bytes | 
| コンパイル時間 | 1,242 ms | 
| コンパイル使用メモリ | 104,276 KB | 
| 実行使用メモリ | 20,500 KB | 
| 最終ジャッジ日時 | 2024-06-26 17:35:39 | 
| 合計ジャッジ時間 | 13,521 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 39 TLE * 1 -- * 8 | 
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <bitset>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#define rep(i,n) for(i=0; i<n; ++i)
#define inc_rep(i,a,n) for(i=a; i<=n; ++i)
#define dec_rep(i,n,a) for(i=n; i>=a; --i)
#define in(a) cin >> a
#define out(a,b) cout << a << b
#define print_vec(v) for(auto it=v.begin();it!=v.end();++it)cout<<*it <<" ";cout<<endl
#define print_vec2d(v) for(int i=0;i<v.size();++i){for(int j=0;j<v[i].size();++j)cout<<v[i][j]<<" ";cout<<endl;}cout<<endl
#define print_vecpair(v) for(int i=0;i<v.size();++i)cout<<v[i].first<<" "<<v[i].second<<endl
#define vin(v) for(int i=0;i<v.size();++i)cin>>v[i]
#define v2din(v) for(int i=0;i<v.size();++i){for(int j=0;j<v[i].size();++j)cin>>v[i][j];}
#define vpairin(v) for(int i=0;i<v.size();++i){int a,b;cin>>a>>b;v[i]=make_pair(a,b);}
using namespace std;
using lint = long long;
typedef struct {
    lint hi;
    // previously: not scored, scored
    pair<lint, lint> sc;
    // next, score
    vector<pair<lint, lint> > gt;
} gr;
int main(void){
    lint i, j;
    lint k, cnt=0, x, y;
    lint p, q, n, m;
    string s;
    in(n);in(m);
    vector<gr> vc(n);
    vector<gr> vz(n);
    rep(i,n){
        lint a;
        in(a);
        vc[i].hi=a;
        vz[i].hi=a;
        vc[i].sc.first=-1;
        vz[i].sc.first=-1;
        vc[i].sc.second=-1;
        vz[i].sc.second=-1;
    }
    rep(i,m){
        in(x);in(y);
        x--;y--;
        // if(vc[y].hi-vc[x].hi>0) vc[x].gt.push_back(make_pair(y, vc[y].hi-vc[x].hi));
        // else vc[x].gt.push_back(make_pair(y, 0));
        // if(vz[x].hi-vz[y].hi>0) vz[y].gt.push_back(make_pair(x, vz[x].hi-vz[y].hi));
        // else vz[y].gt.push_back(make_pair(x, 0));
        // vz[y].gt.push_back(x);
        vc[x].gt.push_back(make_pair(y, vc[y].hi-vc[x].hi));
        vz[y].gt.push_back(make_pair(x, vz[x].hi-vz[y].hi));
    }
    vector<lint> qc={0};
    vc[0].sc.first=0;
    while(!qc.empty()){
        lint cc=qc.back();qc.pop_back();
        // cout << cc << endl;
        rep(i,vc[cc].gt.size()){
            if(vc[cc].gt[i].second<=0){
                if(vc[vc[cc].gt[i].first].sc.first<max(vc[cc].sc.first, vc[cc].sc.second)){
                vc[vc[cc].gt[i].first].sc.first=max(vc[cc].sc.first, vc[cc].sc.second);
                qc.push_back(vc[cc].gt[i].first);}
            }
            else{
                if(vc[cc].sc.first>-1&&vc[vc[cc].gt[i].first].sc.second<vc[cc].sc.first+vc[cc].gt[i].second){
                vc[vc[cc].gt[i].first].sc.second=vc[cc].sc.first+vc[cc].gt[i].second;
                qc.push_back(vc[cc].gt[i].first);}
            }
        }
    }
    vector<lint> qz={n-1};
    vz[n-1].sc.first=0;
    // lint cz=n-1;
    while(!qz.empty()){
        lint cz=qz.back();qz.pop_back();
        rep(i,vz[cz].gt.size()){
            if(vz[cz].gt[i].second<=0){
                if(vz[vz[cz].gt[i].first].sc.first<max(vz[cz].sc.first, vz[cz].sc.second)){
                vz[vz[cz].gt[i].first].sc.first=max(vz[cz].sc.first, vz[cz].sc.second);
                qz.push_back(vz[cz].gt[i].first);}
            }
            else{
                if(vz[cz].sc.first>-1&&vz[vz[cz].gt[i].first].sc.second<vz[cz].sc.first+vz[cz].gt[i].second){
                vz[vz[cz].gt[i].first].sc.second=vz[cz].sc.first+vz[cz].gt[i].second;
                qz.push_back(vz[cz].gt[i].first);}
            }
        }
    }
    out(max(vc[n-1].sc.first, vc[n-1].sc.second),endl);
    out(max(vz[0].sc.first, vz[0].sc.second),endl);
    // cout << vc[0].sc.first << " " << vc[0].sc.second << endl;
    // cout << vc[1].sc.first << " " << vc[1].sc.second << endl;
    // cout << vc[2].sc.first << " " << vc[2].sc.second << endl;
    return 0;
}