-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathpawns_revenge.cpp
More file actions
77 lines (72 loc) · 1.66 KB
/
pawns_revenge.cpp
File metadata and controls
77 lines (72 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*------------------Honey, you should see me in a crown--------------------*/
#include<bits/stdc++.h>
#define FAST cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0)
#define lli(n) long long n; cin>>n;
#define li(n) long n; cin>>n;
#define inti(n) int n;cin>>n;
#define CC int test;\
cin>>test;\
while(test--)
using namespace std;
int n;
/*------------Every fairy tale needs a good old-fashioned villain----------------*/
bool valid(int v,int u)
{
return (v>=0 && v<n && u>=0 && u<n);
}
int main()
{
FAST;
cin>>n;
char a[n][n];
int x=-10,y=-10;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
{
cin>>a[i][j];
if(a[i][j]=='K')
{
x=i;y=j;
}
}
//cout<<x<<' '<<y<<" place of king\n";
long cost=0;
bool flag=0;
for(int i=0;i<n;i++)//rest
{
if(flag)
break;
for(int j=0;j<n;j++)
{
if(a[i][j]=='*')
{
if(abs(x-i)<=1 && abs(y-j)<=1)
{a[i][j]='-';continue;}
if(valid(i,j+2) && a[i][j+2]=='*' && a[i+1][j+1]=='-')//special case
{
cost++;
//cout<<i<<' '<<j<<" - 2 in 1\n";
a[i][j]='-'; a[i][j+2]='-';
}else{
if(valid(i+1,j-1) && a[i+1][j-1]=='-')
{
cost++;
// cout<<i<<' '<<j<<" clear\n";
}else if(valid(i+1,j+1) && a[i+1][j+1]=='-')
{
cost++;
//cout<<i<<' '<<j<<" clear 2\n";
}
else
{flag=1;break;}
}
}
}
}
if(flag)
{
cout<<"-1\n";
}else
cout<<cost<<'\n';
return 0;
}