Task: | Linear Gimmick |
Sender: | zxc |
Submission time: | 2016-08-04 14:48:54 +0300 |
Language: | C++ |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 100 |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.06 s | details |
#2 | ACCEPTED | 0.05 s | details |
#3 | ACCEPTED | 0.06 s | details |
#4 | ACCEPTED | 0.05 s | details |
#5 | ACCEPTED | 0.07 s | details |
#6 | ACCEPTED | 0.06 s | details |
#7 | ACCEPTED | 0.06 s | details |
#8 | ACCEPTED | 0.08 s | details |
#9 | ACCEPTED | 0.06 s | details |
#10 | ACCEPTED | 0.06 s | details |
#11 | ACCEPTED | 0.06 s | details |
#12 | ACCEPTED | 0.19 s | details |
#13 | ACCEPTED | 0.17 s | details |
#14 | ACCEPTED | 0.32 s | details |
#15 | ACCEPTED | 0.30 s | details |
#16 | ACCEPTED | 0.29 s | details |
#17 | ACCEPTED | 0.06 s | details |
#18 | ACCEPTED | 0.29 s | details |
#19 | ACCEPTED | 0.32 s | details |
#20 | ACCEPTED | 0.32 s | details |
#21 | ACCEPTED | 0.20 s | details |
#22 | ACCEPTED | 0.33 s | details |
#23 | ACCEPTED | 0.20 s | details |
#24 | ACCEPTED | 0.31 s | details |
#25 | ACCEPTED | 0.20 s | details |
#26 | ACCEPTED | 0.20 s | details |
#27 | ACCEPTED | 0.32 s | details |
#28 | ACCEPTED | 0.06 s | details |
#29 | ACCEPTED | 0.06 s | details |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:13:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for(int i = 0; i < s.size(); ++i) { ^
Code
#include <iostream> #include <set> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin>>n; string s; cin>>s; int a = 0; int b = 0; for(int i = 0; i < s.size(); ++i) { if(s[i] != '<') break; ++a; } for(int i = (int)s.size()-1; i >= 0; --i) { if(s[i] != '>') break; ++b; } int lo = 0; int hi = n-1; int best = 0; while(lo <= hi) { int mid = (lo+hi)/2; set<int> st; for(int i = 0; i < n; ++i) { st.insert(st.end(), i); } int pos = mid; int moves = 0; int pois = 0; while(1) { st.erase(pos); ++moves; if(st.size() == 0) { cout<<n<<endl; return 0; } if(s[pos] == '<') { auto x = st.lower_bound(pos); if(x == st.begin()) { pos = 0; break; } --x; pos = *x; } else { auto x = st.lower_bound(pos); if(x == st.end()) { pois = 1; break; } pos = *x; } } best = max(moves, best); if(pois == 0) { lo = mid+1; } else { hi = mid-1; } } cout<<best<<endl; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
5 >>><> |
correct output |
---|
5 |
user output |
---|
5 |
Test 2
Verdict: ACCEPTED
input |
---|
6 ><><>< |
correct output |
---|
6 |
user output |
---|
6 |
Test 3
Verdict: ACCEPTED
input |
---|
8 >>>><><< |
correct output |
---|
8 |
user output |
---|
8 |
Test 4
Verdict: ACCEPTED
input |
---|
8 >>>>><>> |
correct output |
---|
8 |
user output |
---|
8 |
Test 5
Verdict: ACCEPTED
input |
---|
10 ><<><<<<<< |
correct output |
---|
10 |
user output |
---|
10 |
Test 6
Verdict: ACCEPTED
input |
---|
7 >><><<< |
correct output |
---|
7 |
user output |
---|
7 |
Test 7
Verdict: ACCEPTED
input |
---|
526 ><><<<>><><><<<<<>>>>>><><<>><... |
correct output |
---|
526 |
user output |
---|
526 |
Test 8
Verdict: ACCEPTED
input |
---|
920 <<<<><>>><><><<<<><<<<>>><<>>>... |
correct output |
---|
917 |
user output |
---|
917 |
Test 9
Verdict: ACCEPTED
input |
---|
528 <>>>>>><><<>>>>>>>>>>><>><<<<>... |
correct output |
---|
528 |
user output |
---|
528 |
Test 10
Verdict: ACCEPTED
input |
---|
837 <<<>><<<<><>><<<<<<>><<<<<<><<... |
correct output |
---|
837 |
user output |
---|
837 |
Test 11
Verdict: ACCEPTED
input |
---|
761 >>>><><>>><<><>>>><<<>>>>>>>><... |
correct output |
---|
761 |
user output |
---|
761 |
Test 12
Verdict: ACCEPTED
input |
---|
53592 <><<<<>>><>><<><><><<>><<<<<><... |
correct output |
---|
53591 |
user output |
---|
53591 |
Test 13
Verdict: ACCEPTED
input |
---|
52256 >>><<><>><><<<>><<><>><>>><<>>... |
correct output |
---|
52256 |
user output |
---|
52256 |
Test 14
Verdict: ACCEPTED
input |
---|
99234 >><>><<<<><<><<<<><><><><><<<>... |
correct output |
---|
99234 |
user output |
---|
99234 |
Test 15
Verdict: ACCEPTED
input |
---|
90893 <<><><><<<<><>><<<<>>>><><><><... |
correct output |
---|
90893 |
user output |
---|
90893 |
Test 16
Verdict: ACCEPTED
input |
---|
94064 >><><<>>><<>>>>>><>><<<><>><>>... |
correct output |
---|
94064 |
user output |
---|
94064 |
Test 17
Verdict: ACCEPTED
input |
---|
5 >><<< |
correct output |
---|
5 |
user output |
---|
5 |
Test 18
Verdict: ACCEPTED
input |
---|
85155 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<... |
correct output |
---|
84901 |
user output |
---|
84901 |
Test 19
Verdict: ACCEPTED
input |
---|
97153 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<... |
correct output |
---|
96645 |
user output |
---|
96645 |
Test 20
Verdict: ACCEPTED
input |
---|
99451 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<... |
correct output |
---|
99140 |
user output |
---|
99140 |
Test 21
Verdict: ACCEPTED
input |
---|
56288 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<... |
correct output |
---|
56150 |
user output |
---|
56150 |
Test 22
Verdict: ACCEPTED
input |
---|
93160 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<... |
correct output |
---|
92348 |
user output |
---|
92348 |
Test 23
Verdict: ACCEPTED
input |
---|
69172 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<... |
correct output |
---|
53872 |
user output |
---|
53872 |
Test 24
Verdict: ACCEPTED
input |
---|
94056 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<... |
correct output |
---|
89998 |
user output |
---|
89998 |
Test 25
Verdict: ACCEPTED
input |
---|
71927 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<... |
correct output |
---|
58103 |
user output |
---|
58103 |
Test 26
Verdict: ACCEPTED
input |
---|
72348 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<... |
correct output |
---|
70369 |
user output |
---|
70369 |
Test 27
Verdict: ACCEPTED
input |
---|
97095 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<... |
correct output |
---|
93334 |
user output |
---|
93334 |
Test 28
Verdict: ACCEPTED
input |
---|
6 ><<><< |
correct output |
---|
6 |
user output |
---|
6 |
Test 29
Verdict: ACCEPTED
input |
---|
7 <<><<>> |
correct output |
---|
5 |
user output |
---|
5 |