QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#508906#4925. Adjacent PairsWansur0 1ms5676kbC++231.4kb2024-08-07 21:42:362024-08-07 21:42:36

Judging History

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

  • [2024-08-07 21:42:36]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:5676kb
  • [2024-08-07 21:42:36]
  • 提交

answer

#include <bits/stdc++.h>
#define ent '\n'
#define  f first
#define s second
#define int long long
#define sz(x) (int)(x).size()
#define rep(i, a, b) for(int i = a; i < (b); ++i)

using namespace std;
typedef long long ll;
typedef vector<int> vi;
const int maxn = 2e5 + 12;
const int mod = 1e9 + 7;

int a[maxn];
int b[maxn];
int n, m, k;

int solve(int a[], int x, int y){
    int ans = 0;
    for(int i=1;i<=n;i++){
        if(a[i] == x){
            swap(x, y);
            continue;
        }
        ans++;
        if(a[i+1] == x){
            int j = i + 1;
            while(j + 1 < n && a[j+1] == x + y - ans){
                j++;
            }
            for(int l=i+1;l<=j;l++){
                a[l] = x + y - a[l];
                ans++;
            }
        }
        a[i] = x;
        swap(x, y);
    }
    return ans;
}

void solve(){
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> a[i];
    }
    int ans = 2 * n;
    for(int x=1;x<=n+2;x++){
        for(int y=1;y<=n+2;y++){
            if(x == y) continue;
            for(int i=1;i<=n;i++){
                b[i] = a[i];
            }
            ans = min(ans, solve(b, x, y));
        }
    }
    cout << ans << ent;
}

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

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 20
Accepted
time: 0ms
memory: 3556kb

input:

2
5
4 5 2 4 5
2
1 2

output:

3
0

result:

ok 2 lines

Test #2:

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

input:

1
9
1 2 1 2 3 1 2 1 2

output:

5

result:

wrong answer 1st lines differ - expected: '6', found: '5'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%