# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
802048 | 2023-08-02T09:22:04 Z | guagua0407 | Group Photo (JOI21_ho_t3) | C++17 | 1 ms | 340 KB |
//#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int,int> #define f first #define s second #define all(x) x.begin(),x.end() #define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); void setIO(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } const int mxn=5005; int pos[mxn]; int num[mxn]; ll dp[mxn]; int bit[mxn]; void update(int pos,int val){ for(;pos<mxn;pos+=(pos&-pos)){ bit[pos]+=val; } } int query(int pos){ int ans=0; for(;pos;pos-=(pos&-pos)){ ans+=bit[pos]; } return ans; } int main() {_ int n; cin>>n; for(int i=1;i<=n;i++){ cin>>num[i]; pos[num[i]]=i; } for(int i=1;i<=n;i++){ memset(bit,0,sizeof(bit)); ll cur=0; dp[i]=(ll)1e18; for(int j=i;j>=1;j--){ if(num[j]>i or num[j]<j) cur+=i-j; if(pos[j]>i) cur+=pos[j]-i; else{ int ord=query(n)-query(pos[j]); cur+=ord; } //cout<<j<<' '<<i<<' '<<cur<<'\n'; dp[i]=min(dp[i],dp[j-1]+cur); update(pos[j],1); } } cout<<dp[n]<<'\n'; return 0; } //maybe its multiset not set
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |