結果
| 問題 |
No.2490 Escalator
|
| コンテスト | |
| ユーザー |
Sillpherth
|
| 提出日時 | 2025-04-20 17:44:21 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,078 bytes |
| コンパイル時間 | 695 ms |
| コンパイル使用メモリ | 26,240 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-04-20 17:44:30 |
| 合計ジャッジ時間 | 7,587 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 3 |
| other | WA * 31 RE * 42 |
コンパイルメッセージ
main.c: In function ‘main’:
main.c:51:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
51 | scanf("%d", &N);
| ^~~~~~~~~~~~~~~
main.c:52:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
52 | scanf("%s", s);
| ^~~~~~~~~~~~~~
ソースコード
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
void toBitarray(const char* s, bool* S, int k, int fullN) {
for (int i = 0; i < k - 1; i++) {
S[i] = true;
}
for (int i = k - 1; i < fullN; i++) {
S[i] = (s[i - k + 1] == '1');
}
}
int minFind(const char* s, int N, int n) {
int weightMin = (n + 1) / 2;
int fullN = N + weightMin - 1;
int change = 0;
int HWeight = 0;
bool S[fullN];
toBitarray(s, S, weightMin, fullN);
for (int i = 0; i < n; i++) {
HWeight += S[i] ? 1 : 0;
}
if (HWeight < weightMin) {
S[n - 1] = true;
HWeight++;
change++;
}
for (int i = 1; i < fullN - n + 1; i++) {
HWeight -= S[i - 1] ? 1 : 0;
HWeight += S[i + n - 1] ? 1 : 0;
if (HWeight < weightMin) {
S[i + n - 1] = true;
HWeight++;
change++;
}
}
return change;
}
int main() {
int N;
char s[1001];
scanf("%d", &N);
scanf("%s", s);
printf("%d\n", minFind(s, N, 3));
return 0;
}
Sillpherth