結果
| 問題 |
No.884 Eat and Add
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2019-09-14 03:17:59 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 1,000 ms |
| コード長 | 890 bytes |
| コンパイル時間 | 558 ms |
| コンパイル使用メモリ | 82,952 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-04 19:00:37 |
| 合計ジャッジ時間 | 1,264 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 9 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:42:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
42 | scanf("%s", s + 1);
| ~~~~~^~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 884.cc: No.884 Eat and Add - yukicoder
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
/* constant */
const int MAX_N = 200000;
/* typedef */
/* global variables */
char s[MAX_N + 8];
/* subroutines */
/* main */
int main() {
scanf("%s", s + 1);
s[0] = '0';
int n = strlen(s);
//puts(s);
int cnt = 0;
for (int i = n - 1; i >= 0;) {
while (i >= 0 && s[i] == '0') i--;
if (i < 0) break;
int j = i;
while (s[j] == '1') j--;
int l = i - j;
if (l > 1) s[j] = '1';
cnt++;
i = j;
}
printf("%d\n", cnt);
return 0;
}
tnakao0123