結果

問題 No.1029 JJOOII 3
ユーザー kotatsugamekotatsugame
提出日時 2020-04-22 03:44:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 803 bytes
コンパイル時間 675 ms
コンパイル使用メモリ 71,168 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-18 07:31:52
合計ジャッジ時間 2,873 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,820 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 5 ms
6,940 KB
testcase_04 AC 12 ms
6,940 KB
testcase_05 AC 59 ms
6,940 KB
testcase_06 AC 41 ms
6,944 KB
testcase_07 AC 48 ms
6,940 KB
testcase_08 AC 48 ms
6,940 KB
testcase_09 AC 38 ms
6,940 KB
testcase_10 AC 44 ms
6,940 KB
testcase_11 AC 51 ms
6,940 KB
testcase_12 AC 35 ms
6,940 KB
testcase_13 AC 57 ms
6,944 KB
testcase_14 AC 62 ms
6,944 KB
testcase_15 AC 35 ms
6,944 KB
testcase_16 AC 40 ms
6,944 KB
testcase_17 AC 46 ms
6,940 KB
testcase_18 AC 49 ms
6,940 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 3 ms
6,940 KB
testcase_21 AC 4 ms
6,944 KB
testcase_22 AC 3 ms
6,940 KB
testcase_23 AC 3 ms
6,944 KB
testcase_24 AC 4 ms
6,940 KB
testcase_25 AC 3 ms
6,944 KB
testcase_26 WA -
testcase_27 AC 3 ms
6,940 KB
testcase_28 AC 3 ms
6,944 KB
testcase_29 AC 3 ms
6,944 KB
testcase_30 AC 3 ms
6,944 KB
testcase_31 AC 4 ms
6,940 KB
testcase_32 AC 53 ms
6,940 KB
testcase_33 AC 56 ms
6,944 KB
testcase_34 AC 53 ms
6,940 KB
testcase_35 AC 51 ms
6,940 KB
testcase_36 AC 50 ms
6,940 KB
testcase_37 AC 2 ms
6,944 KB
testcase_38 AC 3 ms
6,944 KB
testcase_39 AC 2 ms
6,944 KB
testcase_40 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    9 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<algorithm>
using namespace std;
int N,K;
string s[80];
int C[80];
long dp[3<<17];
int cnt[3][80];
main()
{
	cin>>N>>K;
	for(int i=0;i<N;i++)
	{
		cin>>s[i]>>C[i];
		for(int j=0;j<s[i].size();j++)
		{
		    char c=s[i][j];
			cnt[c=='J'?0:c=='O'?1:2][i]++;
		}
	}
	for(int i=0;i<=3*K;i++)dp[i]=4e18;
	dp[0]=0;
	for(int i=0;i<3*K;i++)
	{
		for(int j=0;j<N;j++)
		{
			int nxt=i+cnt[i/K][j];
			if(cnt[i/K][j]<K-i%K)
			{
				dp[nxt]=min(dp[nxt],dp[i]+C[j]);
				continue;
			}
			if(nxt>3*K)
			{
				dp[3*K]=min(dp[3*K],dp[i]+C[j]);
				continue;
			}
			nxt=i;
			for(char c:s[j])
			{
				char dir=nxt/K==0?'J':nxt/K==1?'O':'I';
				if(dir==c)nxt++;
				if(nxt==3*K)break;
			}
			dp[nxt]=min(dp[nxt],dp[i]+C[j]);
		}
	}
	long ans=dp[3*K];
	cout<<(ans<3e18?ans:-1)<<endl;
}
0