結果

問題 No.1029 JJOOII 3
ユーザー kotatsugamekotatsugame
提出日時 2020-04-22 03:43:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 767 bytes
コンパイル時間 698 ms
コンパイル使用メモリ 69,616 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2024-04-18 07:29:12
合計ジャッジ時間 2,692 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 4 ms
5,376 KB
testcase_04 AC 10 ms
5,376 KB
testcase_05 AC 41 ms
5,504 KB
testcase_06 AC 29 ms
5,376 KB
testcase_07 AC 36 ms
5,504 KB
testcase_08 AC 39 ms
5,376 KB
testcase_09 AC 31 ms
5,376 KB
testcase_10 AC 34 ms
5,504 KB
testcase_11 AC 41 ms
5,888 KB
testcase_12 AC 25 ms
5,376 KB
testcase_13 AC 43 ms
5,760 KB
testcase_14 AC 46 ms
5,760 KB
testcase_15 AC 33 ms
5,376 KB
testcase_16 AC 37 ms
5,376 KB
testcase_17 AC 44 ms
5,632 KB
testcase_18 AC 46 ms
5,632 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 3 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 3 ms
5,376 KB
testcase_26 WA -
testcase_27 AC 3 ms
5,376 KB
testcase_28 AC 3 ms
5,376 KB
testcase_29 AC 3 ms
5,376 KB
testcase_30 AC 4 ms
5,376 KB
testcase_31 AC 3 ms
5,376 KB
testcase_32 AC 43 ms
5,888 KB
testcase_33 AC 45 ms
6,144 KB
testcase_34 AC 45 ms
5,888 KB
testcase_35 AC 42 ms
5,888 KB
testcase_36 AC 44 ms
6,016 KB
testcase_37 AC 1 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 2 ms
5,376 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(char c:s[i])
		{
			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