-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
1,414 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// @check-accepted: examples Nsmall no-limits | ||
/** | ||
* author: BERNARD B.01 | ||
**/ | ||
#include <algorithm> | ||
#include <iostream> | ||
#include <map> | ||
#include <set> | ||
#include <vector> | ||
|
||
using namespace std; | ||
|
||
#ifdef B01 | ||
#include "deb.h" | ||
#else | ||
#define deb(...) | ||
#endif | ||
|
||
int main() { | ||
ios::sync_with_stdio(false); | ||
cin.tie(0); | ||
int n; | ||
cin >> n; | ||
vector<int> p(n); | ||
for (int i = 0; i < n; i++) { | ||
cin >> p[i]; | ||
} | ||
int pos = 0; | ||
while (p[pos] != 1) { | ||
pos += 1; | ||
} | ||
for (int i = 0; i < n; i++) { | ||
if (p[(pos + i) % n] != i + 1) { | ||
cout << -1 << '\n'; | ||
return 0; | ||
} | ||
} | ||
cout << (n - pos) % n << '\n'; | ||
return 0; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env python3 | ||
# @check-accepted: examples Nsmall no-limits | ||
from sys import stdin, stdout | ||
|
||
def rd(): return stdin.readline().strip() | ||
def rdl(x): return map(x, rd().split()) | ||
def wt(x): stdout.write(str(x)) | ||
def wtl(x): wt(str(x) + '\n') | ||
|
||
n = int(rd()) | ||
p = list(rdl(int)); | ||
pos = p.index(1) | ||
for i in range(n): | ||
if p[(pos + i) % n] != i + 1: | ||
wtl(-1) | ||
exit() | ||
wtl((n - pos) % n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#include <algorithm> | ||
#include <iostream> | ||
#include <map> | ||
#include <set> | ||
#include <vector> | ||
using namespace std; | ||
|
||
int main() | ||
{ | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
|
||
int t; | ||
cin >> t; | ||
|
||
for(; t; t--) | ||
{ | ||
char mat[9][9]; | ||
for(int i = 0; i <= 7; i++) | ||
for(int j = 0; j <= 7; j++) | ||
cin >> mat[i][j]; | ||
|
||
bool underThreat = 0; | ||
for(int i = 0; i <= 7; i++) | ||
for(int j = 0; j <= 7; j++) | ||
{ | ||
if(mat[i][j] == 'P') // pawn | ||
{ | ||
if(j > 0 && i > 0 && mat[i-1][j-1] == 'q') | ||
underThreat = 1; | ||
if(j < 7 && i > 0 && mat[i-1][j+1] == 'q') | ||
underThreat = 1; | ||
} | ||
if(mat[i][j] == 'N') // knight | ||
{ | ||
for(int dirx = -2; dirx <= 2; dirx++) | ||
for(int diry = -2; diry <= 2; diry++) | ||
{ | ||
if(abs(dirx) + abs(diry) == 3) | ||
{ | ||
if(i + dirx >= 0 && i + dirx <= 7 && j + diry >= 0 && j + diry <= 7) | ||
{ | ||
if(mat[i + dirx][j + diry] == 'q') | ||
underThreat = 1; | ||
} | ||
} | ||
} | ||
} | ||
if(mat[i][j] == 'B' || mat[i][j] == 'Q') // bishop or queen | ||
{ | ||
for(int dirx = -1; dirx <= 1; dirx++) | ||
for(int diry = -1; diry <= 1; diry++) | ||
{ | ||
if(abs(dirx) + abs(diry) == 2) | ||
{ | ||
int xa = i + dirx; | ||
int ya = j + diry; | ||
while(xa >= 0 && xa <= 7 && ya >= 0 && ya <= 7) | ||
{ | ||
if(mat[xa][ya] == 'q') | ||
{ | ||
underThreat = 1; | ||
break; | ||
} | ||
if(mat[xa][ya] != '.') | ||
break; | ||
xa += dirx; | ||
ya += diry; | ||
} | ||
} | ||
} | ||
} | ||
if(mat[i][j] == 'R' || mat[i][j] == 'Q') // rook or queen | ||
{ | ||
for(int dirx = -1; dirx <= 1; dirx++) | ||
for(int diry = -1; diry <= 1; diry++) | ||
{ | ||
if(abs(dirx) + abs(diry) == 1) | ||
{ | ||
int xa = i + dirx; | ||
int ya = j + diry; | ||
while(xa >= 0 && xa <= 7 && ya >= 0 && ya <= 7) | ||
{ | ||
if(mat[xa][ya] == 'q') | ||
{ | ||
underThreat = 1; | ||
break; | ||
} | ||
if(mat[xa][ya] != '.') | ||
break; | ||
xa += dirx; | ||
ya += diry; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
if(underThreat) | ||
cout << "YES\n"; | ||
else | ||
cout << "NO\n"; | ||
} | ||
return 0; | ||
} | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
|
||
def solv(): | ||
board=[] | ||
for i in range(8): | ||
board.append(input()) | ||
for x in range(64): | ||
i=x//8 | ||
j=x%8 | ||
if board[i][j]=='q': | ||
queenx,queeny=i,j | ||
break | ||
#Knight | ||
for x,y in [(1,2),(2,1),(-1,2),(2,-1),(1,-2),(-2,1),(-1,-2),(-2,-1)]: | ||
if 0<=x+queenx<=7 and 0<=y+queeny<=7: | ||
if board[x+queenx][y+queeny]=='N': | ||
print('YES') | ||
return | ||
#Pawn | ||
if 0<=1+queenx<=7 and 0<=1+queeny<=7: | ||
if board[1+queenx][1+queeny]=='P': | ||
print('YES') | ||
return | ||
if 0<=1+queenx<=7 and 0<=-1+queeny<=7: | ||
if board[1+queenx][-1+queeny]=='P': | ||
print('YES') | ||
return | ||
# horizontal/vertical | ||
for a,b in [(0,1),(1,0),(-1,0),(0,-1)]: | ||
x,y=queenx,queeny | ||
for c in range(1,8): | ||
x+=a | ||
y+=b | ||
if 0 <= y < 8 and 0 <= x < 8: | ||
if board[x][y] !='.': | ||
if board[x][y] in ['R','Q']: | ||
print('YES') | ||
return | ||
else: | ||
break | ||
else: | ||
break | ||
# diagonal but not Pawns | ||
for a,b in [(1,1),(1,-1),(-1,1),(-1,-1)]: | ||
x,y=queenx,queeny | ||
for c in range(1,8): | ||
x+=a | ||
y+=b | ||
if 0 <= y < 8 and 0 <= x < 8: | ||
if board[x][y] !='.': | ||
if board[x][y] in ['B','Q']: | ||
print('YES') | ||
return | ||
else: | ||
break | ||
else: | ||
break | ||
print('NO') | ||
|
||
|
||
|
||
T = int(input().strip()) | ||
for _ in range(T): | ||
solv() |
Oops, something went wrong.