結果

問題 No.608 God's Maze
ユーザー pinpin
提出日時 2017-12-08 18:38:53
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,853 bytes
コンパイル時間 1,017 ms
コンパイル使用メモリ 84,604 KB
実行使用メモリ 8,276 KB
最終ジャッジ日時 2023-08-19 22:37:08
合計ジャッジ時間 3,900 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,400 KB
testcase_01 WA -
testcase_02 AC 2 ms
5,392 KB
testcase_03 AC 2 ms
5,448 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
5,560 KB
testcase_08 AC 2 ms
5,388 KB
testcase_09 AC 2 ms
5,432 KB
testcase_10 WA -
testcase_11 AC 2 ms
5,452 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 2 ms
5,504 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 2 ms
5,456 KB
testcase_18 AC 2 ms
5,428 KB
testcase_19 AC 2 ms
5,456 KB
testcase_20 AC 2 ms
5,444 KB
testcase_21 AC 2 ms
5,452 KB
testcase_22 AC 2 ms
5,560 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 2 ms
5,656 KB
testcase_26 AC 2 ms
5,404 KB
testcase_27 AC 2 ms
5,436 KB
testcase_28 AC 2 ms
5,404 KB
testcase_29 AC 5 ms
8,004 KB
testcase_30 WA -
testcase_31 AC 4 ms
7,816 KB
testcase_32 WA -
testcase_33 AC 5 ms
8,144 KB
testcase_34 WA -
testcase_35 AC 2 ms
5,768 KB
testcase_36 AC 2 ms
5,664 KB
testcase_37 WA -
testcase_38 AC 5 ms
7,840 KB
testcase_39 AC 3 ms
5,460 KB
testcase_40 WA -
testcase_41 AC 3 ms
5,816 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 5 ms
7,876 KB
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 AC 5 ms
7,900 KB
testcase_49 AC 3 ms
5,848 KB
testcase_50 AC 2 ms
5,452 KB
testcase_51 AC 2 ms
5,396 KB
testcase_52 AC 2 ms
5,452 KB
testcase_53 AC 2 ms
5,696 KB
testcase_54 AC 2 ms
5,600 KB
testcase_55 AC 2 ms
5,524 KB
testcase_56 AC 2 ms
5,396 KB
testcase_57 AC 2 ms
5,484 KB
testcase_58 AC 2 ms
5,448 KB
testcase_59 AC 2 ms
5,448 KB
testcase_60 AC 2 ms
5,388 KB
testcase_61 AC 2 ms
5,716 KB
testcase_62 AC 2 ms
5,456 KB
testcase_63 AC 2 ms
5,392 KB
testcase_64 AC 2 ms
5,432 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[1000005], T[1000005];
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 || (id == n && start[1] != 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 if (id>n || (id == n && start[0] != n)){
        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;
        }
    }
    else if (S[id] == 1) ans = 3;

    cout << ans << endl;
}
0