結果
| 問題 |
No.3266 岩井星人は見ずにはいられない
|
| コンテスト | |
| ユーザー |
pengin_2000
|
| 提出日時 | 2025-09-06 14:42:05 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 1,025 bytes |
| コンパイル時間 | 221 ms |
| コンパイル使用メモリ | 25,856 KB |
| 実行使用メモリ | 6,272 KB |
| 最終ジャッジ日時 | 2025-09-06 14:42:06 |
| 合計ジャッジ時間 | 1,299 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 31 |
コンパイルメッセージ
main.c: In function ‘main’:
main.c:6:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
6 | scanf("%lld %lld", &n, &a);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
main.c:7:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
7 | scanf("%s", s);
| ^~~~~~~~~~~~~~
ソースコード
#include<stdio.h>
char s[200005], t[400005];
int main()
{
long long int n, a;
scanf("%lld %lld", &n, &a);
scanf("%s", s);
long long int cnt1 = 0;
long long int m = 0;
long long int i;
for (i = 0; i < n; i++)
{
t[m] = s[i];
if (m > 0)
{
if (t[m - 1] == '0' && t[m] == '1')
{
m--;
cnt1++;
continue;
}
}
m++;
}
long long int c[2] = { 0,0 };
for (i = 0; i < m; i++)
c[t[i] - '0']++;
long long int cnt2 = c[0];
if (cnt2 > c[1])
cnt2 = c[1];
cnt2 += cnt1;
if (a <= cnt1)
{
long long int r = 1200;
for (i = 0; a > 0; i++)
{
if (s[i] == '0')
r--;
else
{
if (r < 1200)
{
r++;
a--;
}
}
}
printf("%lld\n", i);
return 0;
}
long long int ans = n;
a -= cnt1;
ans += a / cnt2 * n;
a %= cnt2;
if (a == 0)
{
ans -= n;
a += cnt2;
}
for (i = 0; a > 0; i++, ans++)
{
t[m] = s[i];
if (m > 0)
{
if (t[m - 1] == '0' && t[m] == '1')
{
m--;
a--;
continue;
}
}
m++;
}
printf("%lld\n", ans);
return 0;
}
pengin_2000