結果

問題 No.3114 0→1
ユーザー AK_Mi
提出日時 2025-04-18 23:24:05
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,189 bytes
コンパイル時間 2,153 ms
コンパイル使用メモリ 193,312 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-04-18 23:24:08
合計ジャッジ時間 3,065 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other WA * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:7:9: warning: ‘before’ may be used uninitialized [-Wmaybe-uninitialized]
    7 |     int before;
      |         ^~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    int now = 0;
    int one = 0;
    int before;
    int count = 0;
    string s;
    
    cin >> n >> s >> count;
    
    for(int i = 0; i < n; i++){
        if(s.at(i) == '0'){
            one = 0;
            now++;
            
        }else if(s.at(i) == '1'){
            if(one == 0){
                if(now % 3 == 0){
                    count += int(now / 3)*2;
                    before = 1;
                }else if(now % 3 == 1){
                    if(before == 1 || one > 1){
                        count += int(now / 3)*2;
                        before = 0;
                    }else{
                        count += int(now / 3)*2 + 1;
                        before = 1;                        
                    }
                }else if(now % 3 == 2){
                    if(before == 1 || one > 1)before = 0;
                    else before = 1;
                    count += int(now / 3)*2 + 1;
                }
                
                now = 0;                
            }
            
            one++;
        }
    }
    

    cout << count << endl;
    
    return 0;
}
0