結果
| 問題 | No.3015 右に寄せろ! | 
| コンテスト | |
| ユーザー |  tnakao0123 | 
| 提出日時 | 2025-01-28 16:00:01 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 14 ms / 2,000 ms | 
| コード長 | 667 bytes | 
| コンパイル時間 | 560 ms | 
| コンパイル使用メモリ | 39,672 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2025-01-28 16:00:04 | 
| 合計ジャッジ時間 | 1,674 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 36 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:29:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   29 |   scanf("%s", s);
      |   ~~~~~^~~~~~~~~
            
            ソースコード
/* -*- coding: utf-8 -*-
 *
 * 3015.cc:  No.3015 蜿ウ縺ォ蟇・○繧・ - yukicoder
 */
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
/* constant */
const int MAX_N = 2000000;
/* typedef */
using ll = long long;
/* global variables */
char s[MAX_N + 4];
/* subroutines */
/* main */
int main() {
  scanf("%s", s);
  int n = strlen(s);
  ll sum = 0;
  for (int i = 0, x = 0; i < n;) {
    int l1 = 0, l0 = 0;
    while (i < n && s[i] == '1') i++, l1++;
    while (i < n && s[i] == '0') i++, l0++;
    if (l0 > 0 && l1 > 0) {
      x += l1 / 2;
      sum += (ll)x * l0;
    }
  }
  printf("%lld\n", sum);
  return 0;
}
            
            
            
        