結果

問題 No.158 奇妙なお使い
ユーザー fumofumofunifumofumofuni
提出日時 2020-12-17 22:16:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,883 bytes
コンパイル時間 2,119 ms
コンパイル使用メモリ 213,464 KB
実行使用メモリ 389,068 KB
最終ジャッジ日時 2023-10-21 07:12:59
合計ジャッジ時間 14,082 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 321 ms
388,820 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 320 ms
388,820 KB
testcase_04 AC 319 ms
389,068 KB
testcase_05 AC 319 ms
388,820 KB
testcase_06 AC 321 ms
388,820 KB
testcase_07 AC 331 ms
388,820 KB
testcase_08 AC 321 ms
388,820 KB
testcase_09 AC 329 ms
388,820 KB
testcase_10 AC 319 ms
388,832 KB
testcase_11 AC 315 ms
388,820 KB
testcase_12 WA -
testcase_13 AC 319 ms
388,820 KB
testcase_14 AC 320 ms
388,832 KB
testcase_15 AC 319 ms
388,848 KB
testcase_16 AC 323 ms
388,824 KB
testcase_17 WA -
testcase_18 AC 327 ms
388,856 KB
testcase_19 AC 327 ms
388,824 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 317 ms
388,820 KB
testcase_26 AC 320 ms
388,828 KB
testcase_27 AC 320 ms
388,820 KB
testcase_28 AC 321 ms
388,844 KB
testcase_29 AC 318 ms
388,824 KB
testcase_30 AC 320 ms
388,960 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:25:14: warning: overflow in conversion from 'double' to 'll' {aka 'int'} changes value from '4.0e+18' to '2147483647' [-Woverflow]
   25 | const ll INF=4e18;
      |              ^~~~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=int;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={0,1,-1,0,1,1,-1,-1,0};
const ll dx[9]={1,0,0,-1,1,-1,1,-1,0};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll base[3]={0,101,10001};
vl decode(ll n){
    vl ret(3);
    ret[2]=n%base[2];n/=base[2];ret[1]=n%base[1];n/=base[1];ret[0]=n;
    return ret;
}
ll calc(ll hash,ll p){
    vl z=decode(hash);
    ll k=p/1000;ll t=z[0];
    z[0]=max(z[0]-k,0);
    p-=(t-z[0])*1000;
    k=p/100;t=z[1];
    z[1]=max(z[1]-k,0);
    p-=(t-z[1])*100;
    if(p<=z[2]){
        z[2]-=p;
        ll ret=0;
        rep(i,3){ret*=base[i];ret+=z[i];}
        return ret;
    }
    else return -1;
}

vl topsort(vvl &g){
    ll n=g.size();
    vl ans,ind(n);
    rep(i,n)for(auto e:g[i])ind[e]++;
    queue<ll> que;
    rep(i,n)if(!ind[i])que.push(i);
    while(!que.empty()){
        ll v=que.front();que.pop();
        ans.pb(v);
        for(auto nv:g[v]){
            ind[nv]--;if(!ind[nv])que.push(nv);
        }
    }
    return ans;
}

int main(){
    ll s=0;
    rep(i,3){s*=base[i];ll t;cin >> t;s+=t;}
    ll b,x=0;cin >> b;
    rep(i,3){x*=base[i];ll t;cin >> t;x+=t;}
    ll c,y=0;cin >> c;
    rep(i,3){y*=base[i];ll t;cin >> t;y+=t;}
    vector<bool> seen(base[1]*base[2]*10+10);
    queue<ll> que;
    seen[s]=true;que.push(s);
    vvl g(base[1]*base[2]*10+10);
    while(!que.empty()){
        ll p=que.front();que.pop();
        //for(auto x:decode(p))cout << x <<" ";cout << endl;
        ll k=calc(p,b);
        if(k!=-1){
            k+=x;
            if(seen[k])continue;
            que.push(k);seen[k]=true;
            g[p].pb(k);
        }
        k=calc(p,c);
        if(k!=-1){
            k+=y;
            if(seen[k])continue;
            que.push(k);seen[k]=true;
            g[p].pb(k);
        }
    }
    vl ts=topsort(g);
    vl dist(base[1]*base[2]*10+10);
    dist[s]=0;
    for(auto p:ts){
        for(auto to:g[p]){
            chmax(dist[to],dist[p]+1);
        }
    }
    cout << *max_element(all(dist)) <<endl;
}       
0