# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
942029 | Tsagana | Group Photo (JOI21_ho_t3) | C++14 | 1 ms | 348 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define all(x) x.begin(), x.end()
#define int long long
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define mset multiset
#define F first
#define S second
using namespace std;
void solve ()
{
int n; cin >> n;
vector<int > v;
int pos[5001];
for (int i = 1; i <= n; i++)
{
int x; cin >> x;
v.pb(x);
pos[x] = i;
}
int ans = 0;
for (int i = 1; i < v.size(); i++)
{
if (v[i] != n && pos[v[i]] > pos[v[i]+1])
{
int l = pos[v[i]+1];
int r = pos[v[i]];
for (int j = r-1; j > l; j--)
{
pos[v[j-1]]++;
ans++;
}
pos[v[i]] = pos[v[i]+1]+1;
}
}
cout << ans;
}
signed main(){IOS solve(); return 0;}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |