結果

問題 No.1029 JJOOII 3
ユーザー kotatsugamekotatsugame
提出日時 2020-04-22 03:37:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 818 bytes
コンパイル時間 615 ms
コンパイル使用メモリ 69,744 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2024-04-18 06:41:19
合計ジャッジ時間 3,928 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 8 ms
5,376 KB
testcase_04 AC 22 ms
5,376 KB
testcase_05 AC 96 ms
5,760 KB
testcase_06 AC 70 ms
5,376 KB
testcase_07 AC 87 ms
5,632 KB
testcase_08 AC 93 ms
5,632 KB
testcase_09 AC 82 ms
5,376 KB
testcase_10 AC 86 ms
5,376 KB
testcase_11 AC 106 ms
5,888 KB
testcase_12 AC 58 ms
5,376 KB
testcase_13 AC 110 ms
5,888 KB
testcase_14 AC 111 ms
5,888 KB
testcase_15 AC 74 ms
5,376 KB
testcase_16 AC 85 ms
5,376 KB
testcase_17 AC 100 ms
5,760 KB
testcase_18 AC 102 ms
5,760 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 4 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 4 ms
5,376 KB
testcase_28 AC 3 ms
5,376 KB
testcase_29 AC 3 ms
5,376 KB
testcase_30 AC 3 ms
5,376 KB
testcase_31 AC 3 ms
5,376 KB
testcase_32 AC 114 ms
6,016 KB
testcase_33 AC 118 ms
6,144 KB
testcase_34 AC 115 ms
6,016 KB
testcase_35 AC 117 ms
6,016 KB
testcase_36 AC 115 ms
5,888 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 1 ms
5,376 KB
testcase_39 AC 1 ms
5,376 KB
testcase_40 AC 1 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(i/K==nxt/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)
			{
				dp[3*K]=min(dp[3*K],dp[i]+C[j]);
			}
			else
			{
				dp[nxt]=min(dp[nxt],dp[i]+C[j]);
			}
		}
	}
	long ans=dp[3*K];
	cout<<(ans<3e18?ans:-1)<<endl;
}
0