東京大学プログラミングコンテスト2014

Submission #3450716

Source codeソースコード

#include<bits/stdc++.h>
using namespace std;
#define ll long long
 
struct node{
  ll to[10];
  ll sum;
  ll max;
};
 
vector<node> v(2);
node t;

string a;
ll b;
ll dfs(ll n,ll k){
  if(k==a.size()){
    v[n].sum+=b;
    return v[n].max+v[n].sum;
  }
  
  ll ta=a[k]-'0';
  if(v[n].to[ta]==0){
    v[n].to[ta]=v.size();
    v.push_back(t);
  }
  ll tmp=dfs(v[n].to[ta],k+1);
  v[n].max=max(v[n].max,tmp);
  return v[n].sum+v[n].max;
}

int main(){
  ll n;
  cin>>n;
  for(ll i=0;i<n;i++){
    cin>>a>>b;
    reverse(a.begin(),a.end());
    cout<<dfs(1,0)<<endl;
  }
  return 0;
}

Submission

Task問題 E - 宝くじ
User nameユーザ名 shake
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 200
Source lengthソースコード長 624 Byte
File nameファイル名
Exec time実行時間 314 ms
Memory usageメモリ使用量 51684 KB

Test case

Set

Set name Score得点 / Max score Cases
All 200 / 200 scrambled_00.txt,scrambled_01.txt,scrambled_02.txt,scrambled_03.txt,scrambled_04.txt,scrambled_05.txt,scrambled_06.txt,scrambled_07.txt,scrambled_08.txt,scrambled_09.txt,scrambled_10.txt,scrambled_11.txt,scrambled_12.txt,scrambled_13.txt,scrambled_14.txt,scrambled_15.txt,scrambled_16.txt,scrambled_17.txt,scrambled_18.txt,scrambled_19.txt,scrambled_20.txt,scrambled_21.txt,scrambled_22.txt,scrambled_23.txt,scrambled_24.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
scrambled_00.txt AC 2 ms 256 KB
scrambled_01.txt AC 1 ms 256 KB
scrambled_02.txt AC 262 ms 1664 KB
scrambled_03.txt AC 228 ms 1536 KB
scrambled_04.txt AC 259 ms 1664 KB
scrambled_05.txt AC 177 ms 1152 KB
scrambled_06.txt AC 203 ms 1280 KB
scrambled_07.txt AC 65 ms 512 KB
scrambled_08.txt AC 109 ms 768 KB
scrambled_09.txt AC 249 ms 1664 KB
scrambled_10.txt AC 209 ms 1408 KB
scrambled_11.txt AC 67 ms 640 KB
scrambled_12.txt AC 204 ms 1408 KB
scrambled_13.txt AC 49 ms 512 KB
scrambled_14.txt AC 271 ms 27496 KB
scrambled_15.txt AC 13 ms 1912 KB
scrambled_16.txt AC 266 ms 25832 KB
scrambled_17.txt AC 41 ms 8048 KB
scrambled_18.txt AC 249 ms 26472 KB
scrambled_19.txt AC 314 ms 50144 KB
scrambled_20.txt AC 311 ms 51684 KB
scrambled_21.txt AC 200 ms 50148 KB
scrambled_22.txt AC 201 ms 51044 KB
scrambled_23.txt AC 42 ms 12780 KB
scrambled_24.txt AC 89 ms 26600 KB