結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,456 KB
testcase_01 AC 1 ms
5,476 KB
testcase_02 AC 1 ms
5,380 KB
testcase_03 AC 2 ms
5,388 KB
testcase_04 AC 1 ms
5,456 KB
testcase_05 WA -
testcase_06 AC 2 ms
5,432 KB
testcase_07 AC 2 ms
5,524 KB
testcase_08 AC 1 ms
5,668 KB
testcase_09 AC 1 ms
5,384 KB
testcase_10 AC 1 ms
5,528 KB
testcase_11 AC 2 ms
5,380 KB
testcase_12 AC 1 ms
5,384 KB
testcase_13 WA -
testcase_14 AC 2 ms
5,416 KB
testcase_15 WA -
testcase_16 AC 2 ms
5,392 KB
testcase_17 AC 2 ms
5,388 KB
testcase_18 AC 2 ms
5,540 KB
testcase_19 AC 2 ms
5,396 KB
testcase_20 AC 1 ms
5,388 KB
testcase_21 AC 1 ms
5,432 KB
testcase_22 AC 1 ms
5,404 KB
testcase_23 AC 2 ms
5,456 KB
testcase_24 AC 2 ms
5,400 KB
testcase_25 AC 2 ms
5,472 KB
testcase_26 AC 1 ms
5,384 KB
testcase_27 AC 1 ms
5,400 KB
testcase_28 AC 1 ms
5,456 KB
testcase_29 AC 5 ms
8,096 KB
testcase_30 AC 4 ms
7,916 KB
testcase_31 AC 3 ms
7,868 KB
testcase_32 AC 3 ms
8,100 KB
testcase_33 AC 4 ms
7,964 KB
testcase_34 AC 4 ms
7,848 KB
testcase_35 AC 2 ms
5,492 KB
testcase_36 AC 3 ms
5,556 KB
testcase_37 AC 3 ms
5,676 KB
testcase_38 AC 4 ms
7,864 KB
testcase_39 AC 2 ms
5,552 KB
testcase_40 AC 2 ms
5,764 KB
testcase_41 AC 2 ms
5,672 KB
testcase_42 AC 5 ms
7,944 KB
testcase_43 AC 2 ms
5,540 KB
testcase_44 AC 5 ms
7,884 KB
testcase_45 AC 4 ms
7,936 KB
testcase_46 AC 2 ms
5,704 KB
testcase_47 AC 2 ms
5,688 KB
testcase_48 AC 5 ms
7,952 KB
testcase_49 AC 2 ms
5,540 KB
testcase_50 AC 2 ms
5,664 KB
testcase_51 AC 2 ms
5,404 KB
testcase_52 AC 2 ms
5,408 KB
testcase_53 AC 2 ms
5,388 KB
testcase_54 AC 1 ms
5,384 KB
testcase_55 AC 2 ms
5,416 KB
testcase_56 AC 2 ms
5,380 KB
testcase_57 AC 2 ms
5,436 KB
testcase_58 AC 1 ms
5,400 KB
testcase_59 AC 1 ms
5,420 KB
testcase_60 AC 1 ms
5,456 KB
testcase_61 AC 1 ms
5,380 KB
testcase_62 AC 2 ms
5,444 KB
testcase_63 AC 2 ms
5,384 KB
testcase_64 AC 2 ms
5,456 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;
        }
    }
    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