QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#535774#8904. Рекорды и антирекордыMispertion#0 12ms3680kbC++232.3kb2024-08-28 14:35:032024-08-28 14:35:03

Judging History

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

  • [2024-08-28 14:35:03]
  • 评测
  • 测评结果:0
  • 用时:12ms
  • 内存:3680kb
  • [2024-08-28 14:35:03]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
#pragma GCC optimize("Ofast")

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
#define int ll
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mispertion ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define F first
#define S second
#define getlast(s) (*s.rbegin())
#define debg cout << "OK\n"

const ld PI = 3.1415926535;
const int N = 2000 + 10;
const int M = 1e5 + 10;
int mod = 998244353;
const int infi = INT_MAX;
const ll infl = 1e16;
const int P = 2;

int mult(int a, int b){
    return a * 1LL * b % mod;
}

int sum(int a, int b){
    if(a + b >= mod)
        return a + b - mod;
    if(a + b < 0)
        return a + b + mod;
    return a + b;
}

int binpow(int a, int n){
    if (n == 0)
        return 1;
    if (n % 2 == 1){
        return mult(binpow(a, n - 1), a);
    }
    else{
        auto b = binpow(a, n / 2);
        return mult(b, b);
    }
}

int n, a[N], dp[N][N];

void solve(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    dp[0][1] = 1;
    dp[1][0] = 1;
    int ans = 0;
    for(int i = 1; i < n; i++){
        for(int j = 0; j < i; j++){
            for(int nxt = i + 1; nxt <= n; nxt++){
                if(a[i] < a[nxt])
                    dp[nxt][j] = max(dp[nxt][j], dp[i][j] + 1);
                if(a[i] > a[nxt])
                    dp[j][nxt] = max(dp[j][nxt], dp[j][i] + 1);
                if(a[j] < a[nxt] || j == 0)
                    dp[nxt][i] = max(dp[nxt][i], dp[j][i] + 1);
                if(a[j] > a[nxt] || j == 0)
                    dp[i][nxt] = max(dp[i][nxt], dp[i][j] + 1);
            }
            ans = max(ans, dp[i][j]);
            ans = max(ans, dp[j][i]);
        }
    }
    for(int j = 0; j < n; j++)
        ans = max(ans, max(dp[n][j], dp[j][n]));
    for(int i = 0; i <= n; i++)
        for(int j = 0; j <= n; j++)
            dp[i][j] = 0;
    cout << ans << '\n';
}

signed main(){
    mispertion;
    int t = 1;
    cin >> t;
    while (t--){
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 21
Accepted
time: 1ms
memory: 3628kb

input:

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

output:

5
5
5
5
5
4
5
5
5
4
4
5
5
5
4
5
5
4
5
5
4
4
5
5
4
5
4
5
4
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
4
5
5
4
5
5
5
4
5
5
5
5
4
5
5
5
5
5
5
4
5
5
5
5
5
5
4
5
4
5
5
5
5
4
5
5
4
5
4
5
4
5
5
4
4
4
4
5
5
4
4
5
5
5
4
5
4
5
5
5
4
5
4
5
5
4
4
5
5
5
4
5
5
5
5

result:

ok 120 numbers

Test #2:

score: 0
Wrong Answer
time: 1ms
memory: 3680kb

input:

120
16
11 8 4 12 3 6 10 9 7 15 14 2 16 5 1 13
16
9 1 13 14 3 7 5 15 4 11 2 12 8 6 16 10
16
3 12 11 10 5 13 4 8 9 2 7 16 6 14 15 1
16
9 4 7 2 3 8 1 13 5 12 16 14 11 10 6 15
16
14 5 11 10 6 12 7 9 1 16 15 3 4 8 13 2
16
3 13 16 10 5 11 8 4 15 2 9 7 14 1 6 12
16
4 16 7 11 15 5 9 14 8 13 6 3 1 2 12 10
16...

output:

10
10
12
9
11
10
11
12
10
11
9
10
10
9
12
11
12
10
10
12
10
8
11
10
10
11
11
11
10
11
10
10
11
12
11
12
12
10
13
11
11
11
11
10
10
12
10
11
11
9
10
11
10
11
11
13
12
10
11
11
11
10
9
10
12
10
12
11
11
10
11
11
9
12
11
9
11
11
11
12
10
10
12
11
10
11
12
10
9
12
13
10
9
12
11
11
12
11
11
13
11
10
9
10...

result:

wrong answer 19th numbers differ - expected: '9', found: '10'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Wrong Answer

Test #49:

score: 0
Wrong Answer
time: 12ms
memory: 3680kb

input:

9000
8
4 1 2 3 5 6 7 8
12
1 2 12 3 4 5 6 7 8 9 10 11
15
4 1 13 2 15 3 5 6 7 8 9 10 11 12 14
15
4 5 10 14 1 2 3 6 7 8 9 11 12 13 15
9
4 1 2 3 5 6 7 8 9
13
1 4 9 12 2 3 5 6 7 8 10 11 13
14
1 10 2 3 4 5 6 7 8 9 11 12 13 14
15
1 6 7 2 3 4 5 8 9 10 11 12 13 14 15
12
1 4 6 10 12 2 3 5 7 8 9 11
8
7 8 1 2 3...

output:

8
12
13
12
9
11
14
14
9
7
12
15
6
13
8
9
8
11
10
5
7
9
11
12
8
6
14
6
6
10
6
9
8
13
6
14
13
5
6
5
9
13
6
12
14
8
4
13
12
8
9
9
11
9
13
6
6
5
11
11
11
6
5
14
13
14
12
6
14
8
8
9
7
9
15
10
7
14
8
11
5
6
8
12
9
8
12
8
9
10
8
6
10
11
10
15
12
11
12
7
8
7
9
7
13
6
12
5
7
9
10
8
13
6
7
8
13
12
10
5
9
10
7...

result:

wrong answer 4845th numbers differ - expected: '7', found: '8'

Subtask #6:

score: 0
Skipped

Dependency #1:

0%