結果

問題 No.608 God's Maze
ユーザー pinpin
提出日時 2017-12-08 16:46:06
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,747 bytes
コンパイル時間 1,765 ms
コンパイル使用メモリ 84,240 KB
実行使用メモリ 4,608 KB
最終ジャッジ日時 2023-08-19 22:34:39
合計ジャッジ時間 3,094 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 WA -
testcase_02 AC 1 ms
4,384 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 WA -
testcase_11 AC 2 ms
4,380 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 1 ms
4,380 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 4 ms
4,380 KB
testcase_32 WA -
testcase_33 AC 5 ms
4,384 KB
testcase_34 WA -
testcase_35 AC 3 ms
4,380 KB
testcase_36 AC 3 ms
4,380 KB
testcase_37 WA -
testcase_38 AC 4 ms
4,376 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 WA -
testcase_41 AC 3 ms
4,384 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 5 ms
4,376 KB
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 AC 5 ms
4,380 KB
testcase_49 AC 2 ms
4,380 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 WA -
testcase_52 AC 1 ms
4,380 KB
testcase_53 AC 2 ms
4,380 KB
testcase_54 AC 1 ms
4,376 KB
testcase_55 AC 1 ms
4,376 KB
testcase_56 AC 1 ms
4,380 KB
testcase_57 AC 1 ms
4,380 KB
testcase_58 AC 1 ms
4,380 KB
testcase_59 AC 1 ms
4,380 KB
testcase_60 AC 2 ms
4,380 KB
testcase_61 AC 2 ms
4,376 KB
testcase_62 AC 1 ms
4,384 KB
testcase_63 AC 2 ms
4,380 KB
testcase_64 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;

int n;
int S[100005], T[100005];
string s;
int main(void){
    cin >> n >> s;
    S[0] = S[s.size() + 1] = 0;
    for (int i = 1; i <= s.size(); i++){
        T[i] = 0;
        if (s[i - 1] == '.') S[i] = 0;
        else S[i] = 1;
    }

    int start[2] = { n, n };

    for (int i = 1; i <= n; i++){
        if (T[i] == S[i]) continue;
        start[0] = i;
        break;
    }

    for (int i = s.size(); i >= n; i--){
        if (T[i] == S[i]) continue;
        start[1] = i;
        break;
    }

    int id;
    if (n - start[0] < start[1] - n) id = start[0];
    else id = start[1];

    ll ans = 0;
    for (int i = id; i < n; i++){
        T[i] = (T[i] + 1) % 2;
        ans++;
    }
    for (int i = id; i > n; i--){
        T[i] = (T[i] + 1) % 2;
        ans++;
    }

    if (id < n){
        while (T[start[1]] != S[start[1]]){
            if (T[id] == S[id]){
                T[id + 1] = (T[id + 1] + 1) % 2;
                ans++;
                id++;
                continue;
            }
            T[id + 1] = (T[id + 1] + 1) % 2;
            T[id] = (T[id] + 1) % 2;
            ans += 2;
            id++;
        }
    }
    else{
        while (T[start[0]] != S[start[0]]){
            if (T[id] == S[id]){
                T[id - 1] = (T[id - 1] + 1) % 2;
                ans++;
                id--;
                continue;
            }
            T[id - 1] = (T[id - 1] + 1) % 2;
            T[id] = (T[id] + 1) % 2;
            ans += 2;
        }
    }

    cout << ans << endl;
}
0