結果

問題 No.608 God's Maze
ユーザー Sebastian KingSebastian King
提出日時 2017-12-08 02:02:15
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,603 bytes
コンパイル時間 1,244 ms
コンパイル使用メモリ 144,612 KB
実行使用メモリ 5,960 KB
最終ジャッジ日時 2023-08-19 22:28:34
合計ジャッジ時間 3,777 ms
ジャッジサーバーID
(参考情報)
judge10 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,516 KB
testcase_01 AC 1 ms
5,516 KB
testcase_02 AC 1 ms
5,572 KB
testcase_03 AC 2 ms
5,632 KB
testcase_04 AC 2 ms
5,508 KB
testcase_05 AC 1 ms
5,428 KB
testcase_06 AC 1 ms
5,756 KB
testcase_07 AC 1 ms
5,588 KB
testcase_08 AC 2 ms
5,580 KB
testcase_09 AC 2 ms
5,528 KB
testcase_10 AC 1 ms
5,508 KB
testcase_11 AC 1 ms
5,596 KB
testcase_12 AC 2 ms
5,508 KB
testcase_13 AC 2 ms
5,544 KB
testcase_14 AC 2 ms
5,508 KB
testcase_15 AC 2 ms
5,600 KB
testcase_16 AC 1 ms
5,508 KB
testcase_17 AC 1 ms
5,504 KB
testcase_18 AC 1 ms
5,520 KB
testcase_19 AC 1 ms
5,564 KB
testcase_20 AC 1 ms
5,508 KB
testcase_21 AC 1 ms
5,508 KB
testcase_22 AC 1 ms
5,628 KB
testcase_23 AC 2 ms
5,528 KB
testcase_24 AC 2 ms
5,544 KB
testcase_25 AC 2 ms
5,528 KB
testcase_26 AC 2 ms
5,504 KB
testcase_27 AC 1 ms
5,428 KB
testcase_28 AC 1 ms
5,508 KB
testcase_29 AC 3 ms
5,904 KB
testcase_30 AC 3 ms
5,872 KB
testcase_31 AC 2 ms
5,728 KB
testcase_32 AC 3 ms
5,764 KB
testcase_33 AC 4 ms
5,960 KB
testcase_34 AC 3 ms
5,808 KB
testcase_35 AC 2 ms
5,596 KB
testcase_36 AC 2 ms
5,524 KB
testcase_37 AC 2 ms
5,788 KB
testcase_38 AC 3 ms
5,776 KB
testcase_39 AC 2 ms
5,564 KB
testcase_40 AC 3 ms
5,640 KB
testcase_41 AC 2 ms
5,628 KB
testcase_42 AC 3 ms
5,952 KB
testcase_43 AC 2 ms
5,636 KB
testcase_44 AC 4 ms
5,888 KB
testcase_45 AC 3 ms
5,904 KB
testcase_46 AC 2 ms
5,728 KB
testcase_47 AC 1 ms
5,644 KB
testcase_48 AC 3 ms
5,912 KB
testcase_49 AC 2 ms
5,608 KB
testcase_50 AC 1 ms
5,504 KB
testcase_51 AC 1 ms
5,536 KB
testcase_52 AC 2 ms
5,588 KB
testcase_53 AC 2 ms
5,560 KB
testcase_54 AC 2 ms
5,680 KB
testcase_55 AC 2 ms
5,532 KB
testcase_56 AC 2 ms
5,472 KB
testcase_57 AC 1 ms
5,660 KB
testcase_58 AC 1 ms
5,580 KB
testcase_59 AC 1 ms
5,512 KB
testcase_60 AC 1 ms
5,528 KB
testcase_61 AC 1 ms
5,476 KB
testcase_62 AC 1 ms
5,524 KB
testcase_63 AC 1 ms
5,508 KB
testcase_64 AC 2 ms
5,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;

const int MM = 1e9 + 7;
const double eps = 1e-8;
const int MAXN = 2e6 + 10;

int n, m;

void prework(){

}

void read(){

}

char s[MAXN];
int f[MAXN];

int gao(int x){
	for (int i = 1; i <= n; i++)
		f[i] = (s[i] == '#');
	int st = 0;
	for (int i = 1; i <= n; i++)
		if (f[i] == 1){
			st = i;
			break;
		}
	int ed = n + 1;
	for (int i = n; i >= 1; i--)
		if (f[i] == 1){
			ed = i;
			break;
		}
	int ret = 0;
	if (x > st){
		for (x--; x >= st; x--){
			ret++;
			f[x] = 1 - f[x];
			//cout << ret << ' ' << x << endl;
		}
		x++;
	}
	f[n + 1] = 1;
	f[n + 2] = 0;
	//cout << "!!!!  " << st << ' ' << ed << ' ' << ret << ' ' << x << endl;
	while(true){
		if (f[x] == 0){
			ret++;
			x++;
			f[x] = 1 - f[x];
			//cout << ret << ' ' << x << endl;
		}
		else{
			if (x == n){
				ret += 3;
				break;
			}
			ret++;
			x++;
			f[x] = 1 - f[x];
			//cout << ret << ' ' << x << endl;
			ret++;
			x--;
			f[x] = 1 - f[x];
			//cout << ret << ' ' << x << endl;
		}
		if (x >= ed - 1 && f[x] == 0 && (f[x + 1] == 0 || x == n))
			break;
	}
	//cout << "===========  " << ret << endl;
	return ret;
}

void solve(int casi){
//	cout << "Case #" << casi << ": ";
	scanf("%d", &m);
	scanf("%s", s + 1);
	n = strlen(s + 1);
	int ans = gao(m);
	reverse(s + 1, s + n + 1);
	ans = min(ans, gao(n + 1 - m));
	printf("%d", ans);
}

void printans(){

}


int main(){
//	std::ios::sync_with_stdio(false);
	prework();
	int T = 1;
//	cin>>T;
	for(int i = 1; i <= T; i++){
		read();
		solve(i);
		printans();
	}
	return 0;
}

0