ログインしてください。
提出 #26109880
ソースコード 拡げる
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
typedef long long ll;
template <typename T> T Max(T x, T y) { return x > y ? x : y; }
template <typename T> T Min(T x, T y) { return x < y ? x : y; }
template <typename T>
T &read(T &r) {
r = 0; bool w = 0; char ch = getchar();
while(ch < '0' || ch > '9') w = ch == '-' ? 1 : 0, ch = getchar();
while(ch >= '0' && ch <= '9') r = r * 10 + (ch ^ 48), ch = getchar();
return r = w ? -r : r;
}
const int N = 1000100;
int n, ct;
char ch[N], s[N];
signed main() {
read(n);
scanf("%s", ch+1);
int len = strlen(ch+1);
for(int i = 1; i <= n; ++i) ct += ch[i] == '1';
putchar('1');
for(int o = len; o; --o)
if(ch[o] == '0') ch[o] = '1', ++ct;
else {
ch[o] = '0';
--ct;
break ;
}
std::reverse(ch + 1, ch + len + 1);
for(int i = len+1; i <= n; ++i) ch[i] = '0';
std::reverse(ch + 1, ch + n + 1);
for(int i = 1; i <= n; ++i) {
if(!ct) break ;
if(ch[i] == '0') {
s[i] = '0';
for(int o = n; o; --o)
if(ch[o] == '0') ch[o] = '1', ++ct;
else {
ch[o] = '0';
--ct;
break ;
}
}
else s[i] = '1', ch[i] = '0', --ct;
}
printf("%s\n", s+1);
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | C - Binary Strings |
| ユーザ | do_while_true |
| 言語 | C++ (GCC 9.2.1) |
| 得点 | 500 |
| コード長 | 1224 Byte |
| 結果 | AC |
| 実行時間 | 24 ms |
| メモリ | 5696 KiB |
コンパイルエラー
./Main.cpp: In function ‘int main()’:
./Main.cpp:20:7: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
20 | scanf("%s", ch+1);
| ~~~~~^~~~~~~~~~~~
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 500 / 500 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | 00-sample-001.txt, 00-sample-002.txt, 00-sample-003.txt |
| All | 00-sample-001.txt, 00-sample-002.txt, 00-sample-003.txt, 01-001.txt, 01-002.txt, 01-003.txt, 01-004.txt, 01-005.txt, 01-006.txt, 01-007.txt, 01-008.txt, 01-009.txt, 01-010.txt, 01-011.txt, 01-012.txt, 01-013.txt, 01-014.txt, 01-015.txt, 01-016.txt, 01-017.txt, 01-018.txt, 01-019.txt, 01-020.txt, 01-021.txt, 01-022.txt, 01-023.txt, 01-024.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 00-sample-001.txt | AC | 8 ms | 3640 KiB |
| 00-sample-002.txt | AC | 3 ms | 3560 KiB |
| 00-sample-003.txt | AC | 5 ms | 4588 KiB |
| 01-001.txt | AC | 2 ms | 3564 KiB |
| 01-002.txt | AC | 2 ms | 3676 KiB |
| 01-003.txt | AC | 12 ms | 4336 KiB |
| 01-004.txt | AC | 8 ms | 4748 KiB |
| 01-005.txt | AC | 14 ms | 5192 KiB |
| 01-006.txt | AC | 17 ms | 4680 KiB |
| 01-007.txt | AC | 16 ms | 4768 KiB |
| 01-008.txt | AC | 5 ms | 4132 KiB |
| 01-009.txt | AC | 10 ms | 4964 KiB |
| 01-010.txt | AC | 14 ms | 5228 KiB |
| 01-011.txt | AC | 13 ms | 4948 KiB |
| 01-012.txt | AC | 20 ms | 5568 KiB |
| 01-013.txt | AC | 8 ms | 4604 KiB |
| 01-014.txt | AC | 14 ms | 5560 KiB |
| 01-015.txt | AC | 14 ms | 5552 KiB |
| 01-016.txt | AC | 16 ms | 5568 KiB |
| 01-017.txt | AC | 24 ms | 5584 KiB |
| 01-018.txt | AC | 8 ms | 4584 KiB |
| 01-019.txt | AC | 12 ms | 5428 KiB |
| 01-020.txt | AC | 19 ms | 5380 KiB |
| 01-021.txt | AC | 20 ms | 5696 KiB |
| 01-022.txt | AC | 14 ms | 5556 KiB |
| 01-023.txt | AC | 20 ms | 5564 KiB |
| 01-024.txt | AC | 14 ms | 5568 KiB |