QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#508943 | #4925. Adjacent Pairs | Wansur | 0 | 1ms | 5708kb | C++23 | 1.3kb | 2024-08-07 22:16:38 | 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();
}
}
Details
Tip: Click on the bar to expand more detailed information
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%