結果
| 問題 |
No.608 God's Maze
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-12-08 00:39:19 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 1,603 bytes |
| コンパイル時間 | 1,236 ms |
| コンパイル使用メモリ | 157,812 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-29 19:22:25 |
| 合計ジャッジ時間 | 2,866 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 65 |
コンパイルメッセージ
main.cpp: In function ‘void solve(int)’:
main.cpp:82:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
82 | scanf("%d", &m);
| ~~~~~^~~~~~~~~~
main.cpp:83:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
83 | scanf("%s", s + 1);
| ~~~~~^~~~~~~~~~~~~
ソースコード
#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;
}