A title
Title Description
A city is going to play B, A 1 live in the city, B X live in the city, there is now a magical portal from city 1 to the city N turn, there is another odd God portal to the city from the city N 1.
Known, magical portal can go from city went 3 1 2, 2, ... N-1 went to the city city N, but can not enter certain city, God of odd transfer during the transmission of the door is similar.
Well known array a, where ai represents the magic portal can enter the city i (ai = 1 representatives, ai = 0 can not be the representative), and the array b, where bi represents the odd transfer gate can enter God city i.
A magical conch wondering B can go to the city to play.
Known, magical portal can go from city went 3 1 2, 2, ... N-1 went to the city city N, but can not enter certain city, God of odd transfer during the transmission of the door is similar.
Well known array a, where ai represents the magic portal can enter the city i (ai = 1 representatives, ai = 0 can not be the representative), and the array b, where bi represents the odd transfer gate can enter God city i.
A magical conch wondering B can go to the city to play.
Entry
Multiple sets of test samples.
The first row of each test sample with two numbers N and X, represents a number of cities and residential address of B (2 <= N <= 1000 2 <= X <= 1000)
of the second array a given row The third row gives the array b.
The first row of each test sample with two numbers N and X, represents a number of cities and residential address of B (2 <= N <= 1000 2 <= X <= 1000)
of the second array a given row The third row gives the array b.
Export
Feasible, output YES
Otherwise, output NO
Otherwise, output NO
Sample input
5 3
1 1 1 1 1
1 1 1 1 1
5 4
1 0 0 0 1
0 1 1 1 1
5 2
0 1 1 1 1
1 1 1 1 1
Sample Output
YES YES NO
#include <bits/stdc++.h> using namespace std; int a[1000 + 5], b[1000 + 5]; int main() { int n, x; while(~scanf("%d%d", &n, &x)) { for(int i = 1; i <= n; i++) scanf("%d", &a[i]); for(int i = 1; i <= n; i++) scanf("%d", &b[i]); if(a[1] == 0) puts("NO"); else if(a[x] == 1) puts("YES"); else if(b[x] == 0) puts("NO"); else { int ok = 0; for(int i = x + 1; i <= n; i++) { if(a[i] == 1 && b[i] == 1) { ok = 1; break; } } if(ok) puts("YES"); else puts("NO"); } } return 0; }