QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#508947 | #4925. Adjacent Pairs | Wansur | 0 | 1ms | 5664kb | C++23 | 1.3kb | 2024-08-07 22:18:26 | 2024-08-07 22:18:26 |
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 - 1 && a[j + 2] == x){
j += 2;
}
swap(x, y);
ans += (j - i + 1) / 2;
i = j;
}
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: 5664kb
input:
2 5 4 5 2 4 5 2 1 2
output:
3 0
result:
ok 2 lines
Test #2:
score: 20
Accepted
time: 0ms
memory: 3572kb
input:
1 9 1 2 1 2 3 1 2 1 2
output:
6
result:
ok single line: '6'
Test #3:
score: 20
Accepted
time: 0ms
memory: 3556kb
input:
1 7 6 5 4 1 2 6 5
output:
5
result:
ok single line: '5'
Test #4:
score: 0
Wrong Answer
time: 0ms
memory: 3660kb
input:
1 16 4 3 4 3 4 3 4 3 1 4 3 4 1 4 3 4
output:
8
result:
wrong answer 1st lines differ - expected: '10', found: '8'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%