-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswap.cpp
More file actions
59 lines (50 loc) · 1.02 KB
/
swap.cpp
File metadata and controls
59 lines (50 loc) · 1.02 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
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int a[n];
int diff;
string b;
for(int i=0;i<n;i++)
{cin>>a[i];
}
int highest = 0;
cin>>b;
for(int i=0;i<n;i++)
{
diff = a[i] - (i+1);
if(diff>0)
{
// std::string s(diff, '1'); // s == "aaaaa"
//string str = b.substr(i,diff);
// if(str != s) { cout<<"NO\n"; return 0;}
if(highest > i)
{ for(int j = highest; j<i+diff;j++)
{
highest = j;
if(b[j]!='1'){ cout<<"NO\n"; return 0;}
}
}
else
{ for(int j = i; j<i+diff;j++)
{
highest = j;
if(b[j]!='1'){ cout<<"NO\n"; return 0;}
}
}
}
// else if(diff<0)
//{
// std::string s(-1*diff,'1');
// string str = b.substr(i+diff,-1*diff);
// if(str != s) {cout<<"NO\n"; return 0;}
// for(int j = i+diff;j<i;j++)
// {
//if(b[j]!='1') {cout<<"NO\n"; return 0;}
//}
//}
}
cout<<"YES\n";
}