結果
| 問題 |
No.78 クジ付きアイスバー
|
| コンテスト | |
| ユーザー |
YamaKasa
|
| 提出日時 | 2018-10-17 00:41:11 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,738 bytes |
| コンパイル時間 | 2,276 ms |
| コンパイル使用メモリ | 77,276 KB |
| 実行使用メモリ | 54,404 KB |
| 最終ジャッジ日時 | 2024-10-12 18:48:37 |
| 合計ジャッジ時間 | 8,295 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 WA * 1 |
| other | AC * 35 |
ソースコード
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int N = scan.nextInt();
int K = scan.nextInt();
String S = scan.next();
scan.close();
if(K <= N) {
int cnt = 0;
int a = 0;
for(int i = 0; i < N; i++) {
K--;
if(a == 0) {
cnt++;
}else {
a--;
}
if(S.charAt(i) == '1') {
a++;
}else if(S.charAt(i) == '2'){
a += 2;
}
if(K == 0) {
break;
}
}
System.out.println(cnt);
System.exit(0);
}
int a = 0;
int cnt = 0;
for(int i = 0; i < N; i++) {
if(S.charAt(i) == '2') {
a += 2;
}else if(S.charAt(i) == '1') {
a ++;
}
}
if(a >= N) {
cnt = 0;
a = 0;
for(int i = 0; i < N; i++) {
if(a == 0) {
cnt++;
}else {
a--;
}
if(S.charAt(i) == '1') {
a++;
K--;
}else if(S.charAt(i) == '2') {
K -= 2;
a += 2;
}
}
System.out.println(cnt);
System.exit(0);
}
cnt = 0;
int t = N - a;
int c = 0;
int d = 0;
for(int i = 0; i < N; i++) {
if(d == 0) {
c++;
}else {
d--;
}
if(S.charAt(i) == '1') {
d++;
}else if(S.charAt(i) == '2') {
d += 2;
}
}
if(K % N == 0) {
int ans = t * (K / N - 1) + c;
System.out.println(ans);
}else {
int b = K / N;
//System.out.println(c);
int ans = c;
if(b >= 3) {
int e = (b - 1) * (N - a);
ans += e;
}
int res = K - b * N;
//System.out.println(res + " " + d);
for(int i = 0; i < res; i++) {
if(d == 0) {
ans++;
}else {
d--;
}
if(S.charAt(i) == '1') {
d++;
}else if(S.charAt(i) == '2') {
d += 2;
}
}
System.out.println(ans);
}
}
}
YamaKasa