結果

問題 No.78 クジ付きアイスバー
ユーザー tanimani364tanimani364
提出日時 2020-07-09 14:23:56
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,735 bytes
コンパイル時間 2,244 ms
コンパイル使用メモリ 197,256 KB
実行使用メモリ 814,908 KB
最終ジャッジ日時 2024-04-16 08:08:36
合計ジャッジ時間 9,217 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 MLE -
testcase_06 AC 4 ms
6,944 KB
testcase_07 MLE -
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 MLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

void solve()
{
	int n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	int cnt=0,atari=0;
	int pos=0;
	while(pos<n){
		if(atari>0){
			--atari;
		}
		else ++cnt;
		if(s[pos]=='1'){
			++atari;
		}
		else if(s[pos]=='2'){
			atari+=2;
		}
		++pos;
	}
	if(atari>0){
		while(pos<k){
			if(pos>=s.size())s+=s;
			if(atari>0){
				--atari;
			}
			else ++cnt;
			if(s[pos]=='1'){
				++atari;
			}
			else if(s[pos]=='2'){
				atari+=2;
			}
			++pos;
			if(atari>=n)break;
		}
		cout<<cnt<<"\n";
		return;
	}
	int ans=k/n*cnt;
	k%=n;
	pos=0,cnt=0,atari=0;
	while(pos<k){
		if(atari>0){
			--atari;
		}
		else ++cnt;
		if(s[pos]=='1'){
			++atari;
		}
		else if(s[pos]=='2'){
			atari+=2;
		}
		++pos;
	}
	ans+=cnt;
	cout<<ans<<"\n";
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}
0