QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#136166#2418. Inverted DeckNightW0lf#TL 1ms3592kbC++231.1kb2023-08-07 14:53:202023-08-07 14:53:23

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-07 14:53:23]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3592kb
  • [2023-08-07 14:53:20]
  • 提交

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";

}

詳細信息

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...

output:


result: