結果

問題 No.608 God's Maze
ユーザー Sebastian King
提出日時 2017-12-08 00:33:02
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,517 bytes
コンパイル時間 1,288 ms
コンパイル使用メモリ 159,312 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2024-11-29 05:31:42
合計ジャッジ時間 2,946 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 64 WA * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void solve(int)’:
main.cpp:78:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   78 |         scanf("%d", &m);
      |         ~~~~~^~~~~~~~~~
main.cpp:79:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   79 |         scanf("%s", s + 1);
      |         ~~~~~^~~~~~~~~~~~~

ソースコード

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 << endl;
	while(true){
		if (f[x] == 0){
			ret++;
			x++;
			f[x] = 1 - f[x];
			//cout << ret << ' ' << x << endl;
		}
		else{
			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;
	}
	//puts("================");
	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