QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#136166 | #2418. Inverted Deck | NightW0lf# | TL | 1ms | 3592kb | C++23 | 1.1kb | 2023-08-07 14:53:20 | 2023-08-07 14:53:23 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n; cin >> n;
int a[n + 1];
for(int i = 1; i <= n; i++) cin >> a[i];
int st = -1;
int en = -1;
for(int i = n; i > 1; i--) {
if(a[i] < a[i - 1]) {
st = i;
int prev = a[st];
while(st <= n and a[st] <= prev) {
prev = a[st];
st++;
}
st--;
prev = a[st];
en = st;
while(en >= 1 and a[en] >= prev) {
prev = a[en];
en--;
}
en++;
}
}
if(st != -1) {
int l = en;
int r = st;
while(l < r) {
swap(a[l], a[r]);
l++;
r--;
}
}
else {
st = n; en = n;
}
for(int i = 1; i < n; i++) {
if(a[i] > a[i + 1]) {
cout << "impossible\n";
return 0;
}
}
cout << en << " " << st << "\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3580kb
input:
10 1 1 3 2 1 1 1 1 1 1
output:
3 10
result:
ok
Test #2:
score: 0
Accepted
time: 1ms
memory: 3592kb
input:
6 1 1 3 2 4 4
output:
3 4
result:
ok
Test #3:
score: 0
Accepted
time: 1ms
memory: 3468kb
input:
10 1 2 3 6 5 4 7 8 10 9
output:
impossible
result:
ok
Test #4:
score: 0
Accepted
time: 1ms
memory: 3476kb
input:
10 1 2 3 6 5 2 7 8 9 10
output:
impossible
result:
ok
Test #5:
score: -100
Time Limit Exceeded
input:
1000000 4 40 43 52 59 73 112 121 171 172 176 178 191 213 231 232 246 248 260 281 289 293 299 304 305 313 322 328 334 342 350 354 365 368 375 394 396 415 423 438 442 458 477 481 482 488 509 542 551 560 568 577 600 606 607 618 621 624 630 633 641 648 652 664 670 674 700 714 722 731 738 744 752 759 762...