提出 #35596046


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,n) for (ll i=a;i<(ll)n;i++)

const int N=27; // [0,N)

pair<ll,int> f[N][N][N]; // sum, max visit code in path

ll read(){ll r;scanf("%lld",&r);return r;}
const ll INF=0x3f3f3f3f3f3f3f3f;
char t[10];
ll cost[N*N*N+10];
int enc(int a,int b,int c){return c+N*(b+N*a);}
int main(){
  int n=read();
  rep(i,0,n){
    char*s=t+2;
    rep(j,0,2)t[j]=0; // 0 1 2 3 4
    scanf("%s",s);  //     x x x
    int sz=strlen(s);
    rep(j,0,sz)s[j]-='a'-1;
    cost[enc(t[sz-1],t[sz],t[sz+1])]=read();
  }
  rep(i,0,N)rep(j,0,N)rep(k,0,N)f[i][j][k]={-INF,-1};
  ll ans=-INF;
  vector<pair<pair<ll,int>,tuple<int,int,int> > > smabc;
  smabc.push_back({{0,-1},{0,0,0}});
  rep(i,0,smabc.size()){
    auto [sm,abc]=smabc[i];
    auto [s,m]=sm;
    auto [a,b,c]=abc;
    if(f[a][b][c].first > s)continue;
    assert(f[a][b][c].second ==m);
    if(enc(a,b,c)!=0)ans=max(ans,s); // 非起始点
    if(m == enc(a,b,c)){ // || s > 18278* (ll)3000000000){
      printf("Infinity\n");
      return 0;
    }
    rep(ch,1,N){ // a,b,c -> b,c,ch
      ll nc = s+cost[enc(b,c,ch)]; // newcost
      if(c) nc +=cost[enc(0,0,ch)];
      if(b) nc +=cost[enc(0,c,ch)];
      if(f[b][c][ch].first < nc){
        f[b][c][ch] = {nc,max(m,enc(a,b,c))};
        smabc.push_back({f[b][c][ch],{b,c,ch}});
      }
    }
  }
  printf("%lld\n",ans);
  return 0;
}

提出情報

提出日時
問題 G - String Fair
ユーザ cromarmot
言語 C++ (GCC 9.2.1)
得点 600
コード長 1408 Byte
結果 AC
実行時間 48 ms
メモリ 20104 KiB

コンパイルエラー

./Main.cpp: In function ‘ll read()’:
./Main.cpp:10:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   10 | ll read(){ll r;scanf("%lld",&r);return r;}
      |                ~~~~~^~~~~~~~~~~
./Main.cpp: In function ‘int main()’:
./Main.cpp:20:10: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   20 |     scanf("%s",s);  //     x x x
      |     ~~~~~^~~~~~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 600 / 600
結果
AC × 3
AC × 44
セット名 テストケース
Sample example0.txt, example1.txt, example2.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, example0.txt, example1.txt, example2.txt
ケース名 結果 実行時間 メモリ
000.txt AC 15 ms 5700 KiB
001.txt AC 13 ms 4516 KiB
002.txt AC 12 ms 4732 KiB
003.txt AC 14 ms 4656 KiB
004.txt AC 19 ms 12068 KiB
005.txt AC 16 ms 7660 KiB
006.txt AC 18 ms 12080 KiB
007.txt AC 21 ms 11988 KiB
008.txt AC 32 ms 20032 KiB
009.txt AC 12 ms 5784 KiB
010.txt AC 12 ms 5568 KiB
011.txt AC 16 ms 7792 KiB
012.txt AC 13 ms 7784 KiB
013.txt AC 14 ms 7724 KiB
014.txt AC 17 ms 5564 KiB
015.txt AC 18 ms 7796 KiB
016.txt AC 21 ms 7768 KiB
017.txt AC 21 ms 7792 KiB
018.txt AC 16 ms 7788 KiB
019.txt AC 20 ms 7728 KiB
020.txt AC 18 ms 7880 KiB
021.txt AC 20 ms 7800 KiB
022.txt AC 17 ms 7880 KiB
023.txt AC 17 ms 7788 KiB
024.txt AC 22 ms 7728 KiB
025.txt AC 14 ms 5632 KiB
026.txt AC 48 ms 20104 KiB
027.txt AC 15 ms 5624 KiB
028.txt AC 44 ms 20104 KiB
029.txt AC 12 ms 4580 KiB
030.txt AC 12 ms 4652 KiB
031.txt AC 12 ms 4652 KiB
032.txt AC 12 ms 4736 KiB
033.txt AC 14 ms 4516 KiB
034.txt AC 11 ms 4648 KiB
035.txt AC 13 ms 4660 KiB
036.txt AC 14 ms 5816 KiB
037.txt AC 13 ms 4672 KiB
038.txt AC 14 ms 5624 KiB
039.txt AC 12 ms 4732 KiB
040.txt AC 13 ms 5568 KiB
example0.txt AC 12 ms 5548 KiB
example1.txt AC 6 ms 4780 KiB
example2.txt AC 9 ms 4700 KiB