-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1055A.cpp
253 lines (162 loc) · 4.11 KB
/
1055A.cpp
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/** Seek God..Trust God..Praise God..**/
#include<bits/stdc++.h>
using namespace std;
#define fRead(x) freopen("x.txt","r",stdin)
#define fWrite(x) freopen ("x.txt","w",stdout)
#define mt make_tuple
#define ld long double
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define INF 2e16
#define PI acos(-1.0)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<LL,LL>
#define endl "\n";
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define min4(a,b,c,d) min(a,min(b,min(c,d)))
#define max4(a,b,c,d) max(a,max(b,max(c,d)))
#define SQR(a) ((a)*(a))
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define REP(i,b) for(int i=0;i<b;i++)
#define MEM(a,x) memset(a,x,sizeof(a))
#define ABS(x) ((x)<0?-(x):(x))
#define SORT(v) sort(v.begin(),v.end())
#define REV(v) reverse(v.begin(),v.end())
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define Yes cout << "YES" << endl;
#define No cout << "NO" << endl;
#define FASTIO ios_base::sync_with_stdio(0);cin.tie(nullptr);
///..................Sort by second element in a pair in decending order............. ///
bool SortbySecDesc(const pair<long long,long long > &a, const pair<long long,long long > &b)
{
return a.second>b.second;
/*
2 89
1 20
9 11
5 10
5 9
4 7
4 6
*/
}
///..................Sort by second element in a pair in increasing order............. ///
bool SortbySecInc(const pair<long long,long long > &a, const pair<long long,long long > &b)
{
return a.second<b.second;
/*
4 6
4 7
5 9
5 10
9 11
1 20
2 89
*/
}
///.........................first element of pair in descending order..........................//////
bool sortinrev(const pair<int,int> &a,
const pair<int,int> &b)
{
return (a.first > b.first);
/*
9 11
5 10
5 9
4 6
4 7
2 89
1 20
*/
}
///..................................Binary Search in Pair(Pair er 1st element er upor binary search korbe)..................//////
struct compare
{
bool operator()(const pair<int,int> & value, const int &key)
{
return (value.first<key);
}
bool operator()(const int &key, const pair<int,int> &value)
{
return (key<value.first);
}
};
///.............................................................TEMPLATE................................................./////
/// Convert String to Int ////
int String_to_int(string s)
{
stringstream geek(s);
int ans = 0;
geek >> ans;
return ans;
}
/// string to int ///
int S_I(string s)
{
return stoi(s);
}
/*
/// int to string ///
string I_S(int n)
{
return atoi(n);
}
*/
/*
long long Prime[3000000],nPrime;
long long mark[10000002];
void seive(long long int n)
{
long long int i,j,limit=sqrt(n*1.0)+2;
mark[1]=1;
for(i=4; i<=n ;i+=2)
mark[i]=1;
Prime[nPrime++]=2;
for(i=3; i<=n; i+=2)
{
if(!mark[i])
{
Prime[nPrime++]=i;
if(i<=limit)
{
for(j=i*i; j<=n ;j+=i*2)
{
mark[j]=1;
}
}
}
}
}
*/
///std::cin.ingore() used for line of a string///
int main()
{
FASTIO;
ll n, s;
cin >> n >> s;
int a[n+1], b[n+1];
for(int i=0; i<n; i++) cin >> a[i];
for(int i=0; i<n; i++) cin >> b[i];
bool f = 0;
for(int i=s-1; i<=n-1; i++)
{
if(a[i] && b[i])
{
f = 1;
}
}
if((a[0] && f && b[s-1]) || (a[0] && a[s-1]))
{
cout << "YES" << endl;
return 0;
}
cout << "NO" << endl;
return 0;
}