Repository navigation
Expand file tree
/
Copy pathSTPAR.cpp
More file actions
68 lines (63 loc) · 1.38 KB
/
Copy pathSTPAR.cpp
File metadata and controls
68 lines (63 loc) · 1.38 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
#include <bits/stdc++.h>
using namespace std;
int main()
{
long n;
vector<int> q;
while(cin >> n and n > 0)
{
q.resize(n);
for(int i = 0; i < n; i++)
{
int in;
cin >> in;
q[n - i - 1] = in;
}
vector<int> calle;
bool fin_de_cola = false;
int t;
for(int i = 1; i <= n ;)
{
if(!q.empty())
{
t = q.back();
q.pop_back();
}
else
fin_de_cola = true;
/*
cout << i << " " << t << " ";
for(int c : calle)
cout << c;
cout << endl;
*/
if(t != i)
{
if(!calle.empty() and calle.back() == i)
{
calle.pop_back();
q.push_back(t);
i++;
}
else if(fin_de_cola)
{
cout << "no";
break;
}
else
{
calle.push_back(t);
}
}
else
{
i++;
t = 0;
}
if(i > n)
cout << "yes";
}
cout << endl;
}
return 0;
}