QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#508943#4925. Adjacent PairsWansur0 1ms5708kbC++231.3kb2024-08-07 22:16:382024-08-07 22:16:38

Judging History

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

  • [2024-08-07 22:16:38]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:5708kb
  • [2024-08-07 22:16:38]
  • 提交

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 = n;
    for(int i=1;i<=n;i++){
        if(a[i] == x){
            ans--;
            swap(x, y);
            continue;
        }
        if(a[i+1] != x){
            swap(x, y);
            continue;
        }
        int j = i + 1;
        while(j < n && a[j+1] == x + y - a[j]){
            j++;
            swap(x, y);
        }
        ans += (j - i + 1) / 2;
    }
    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: 1ms
memory: 5652kb

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: 5708kb

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%