QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#549955#8837. Increasing Incomeucup-team1069WA 1ms3892kbC++201.9kb2024-09-07 02:23:252024-09-07 02:23:25

Judging History

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

  • [2024-09-07 02:23:25]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3892kb
  • [2024-09-07 02:23:25]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define sz(x) (int)x.size();
#define all(x) x.begin(), x.end();

const int N = 1e2 + 200;
const int inf = 1e9;

int n, p[N];
int go[N], pos[N], dead[N];
vector<int> x[N], y[N];

void solve() {
    cin >> n;
    for (int i = 0; i <= n; ++i) {
        x[i].clear();
        dead[i] = 0;
        y[i].clear();
    }
    vector<int> dp(n + 1, inf), pos(n + 1, 0);
    dp[0] = -inf;
    for (int i = 1; i <= n; ++i) {
        cin >> p[i];
        int j = upper_bound(dp.begin(), dp.end(), p[i]) - dp.begin();
        dp[j] = p[i];
        if (dp[j - 1] >= 1)
            go[i] = pos[dp[j - 1]];
        pos[p[i]] = i;
    }
    vector<int> lis;
    for (int i = n; i >= 1; --i) {
        if (dp[i] != inf) {
            i = pos[dp[i]];
            while (i >= 1) {
                lis.push_back(i);
                i = go[i];
            }
            reverse(lis.begin(), lis.end());
            break;
        }
    }
    vector<int> sil;
    for (int i : lis) {
        sil.push_back(p[i]);
        dead[i] = 1;
    }
    lis.push_back(n + 1);
    sil.push_back(n + 1);
    for (int i = 1; i <= n; ++i) {
        if (dead[i]) continue;
        int j = upper_bound(sil.begin(), sil.end(), p[i]) - sil.begin();
        int k = upper_bound(lis.begin(), lis.end(), i) - lis.begin();
        if (j > k)
            x[j].push_back(p[i]);   
        else
            y[k].push_back(i);
    }
    for (int i = 0; i < lis.size(); ++i) {
        sort(x[i].begin(), x[i].end());
        sort(y[i].begin(), y[i].end());
        for (auto j : x[i]) cout << pos[j] << " ";
        for (auto j : y[i]) cout << j << " ";
        if (lis[i] != n + 1)
            cout << lis[i] << " ";
    }
    cout << '\n';
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int T = 1;
    cin >> T;
    while (T--) solve();
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3892kb

input:

3
3
1 2 3
4
2 4 3 1
5
1 5 2 4 3

output:

1 2 3 
1 3 2 4 
1 3 5 4 2 

result:

ok Correct (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3520kb

input:

153
4
2 4 3 1
4
1 4 2 3
5
2 1 4 5 3
5
1 4 5 3 2
4
1 3 2 4
5
1 5 2 4 3
5
5 3 1 2 4
5
4 1 2 5 3
5
1 2 5 3 4
5
3 1 4 2 5
5
5 4 2 3 1
5
2 1 5 4 3
5
3 4 1 5 2
5
1 4 3 5 2
5
5 1 3 4 2
5
5 3 2 4 1
5
1 5 3 2 4
5
2 4 3 1 5
5
1 5 4 3 2
5
1 2 4 5 3
5
4 2 5 3 1
5
1 3 5 2 4
5
3 1 4 5 2
3
2 1 3
5
1 2 4 3 5
5
5 1 ...

output:

1 3 2 4 
1 3 4 2 
1 2 3 4 5 
1 2 3 4 5 
1 3 2 4 
1 3 5 4 2 
1 3 4 2 5 
1 2 3 5 4 
1 2 4 5 3 
1 2 4 3 5 
1 2 3 4 5 
1 2 5 4 3 
1 2 3 4 5 
1 3 2 4 5 
1 2 3 4 5 
1 2 3 4 5 
1 4 3 5 2 
1 3 2 4 5 
1 5 4 3 2 
1 2 3 4 5 
1 2 4 3 5 
1 4 2 5 3 
1 2 3 4 5 
1 2 3 
1 2 4 3 5 
1 2 3 5 4 
1 2 3 4 5 
1 2 3 5 4 
1 ...

result:

wrong answer Jury found better answer than participant (test case 7)