# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1100477 |
2024-10-14T04:15:31 Z |
Muhammet |
Money (IZhO17_money) |
C++17 |
|
1 ms |
2384 KB |
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
const int N = 1e6 + 5;
int n, b[N], vis[N], in[N];
int main(){
cin >> n;
vector <int> a(n+1);
vector <pair<int,int>> v;
for(int i = 1; i <= n; i++){
cin >> a[i];
v.push_back({a[i],i});
}
sort(v.begin(), v.end());
for(int i = 0; i < n-1; i++){
b[v[i].ff] = v[i+1].ff;
}
int cnt = 0;
for(int i = 1; i <= n; i++){
if(vis[i] == 0){
cnt++;
vis[i] = cnt;
}
if((i < n) and (a[i] == a[i+1] or b[a[i]] == a[i+1])){
vis[i+1] = cnt;
}
}
for(int i = 0; i < n; i++){
in[vis[v[i].ss]] = i;
}
for(int i = 0; i < n-1; i++){
if(vis[v[i].ss] != vis[v[i+1].ss]){
if(vis[in[vis[v[i+1].ss]]+1]+1 == vis[v[i].ss]){
cnt--;
}
}
}
cout << cnt;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |