Submission #583483

#TimeUsernameProblemLanguageResultExecution timeMemory
583483AngusWongGroup Photo (JOI21_ho_t3)C++17
44 / 100
5012 ms320 KiB
#include <bits/stdc++.h> using namespace std; int n, a[5001], p, pos[5001], t, dp[5001], bit[5001]; vector<int> v; void upd(int x){ for (int i=x; i<=n; i+=(i&(-i))) bit[i]++; } int qry(int x){ int ans=0; for (int i=x; i; i-=(i&(-i))) ans+=bit[i]; return ans; } int main() { cin >> n; for (int i=1; i<=n; i++) cin >> a[i]; for (int i=1; i<=n; i++){ dp[i]=2e9; for (int j=1; j<=i; j++){ p=1; v.clear(); v.push_back(-1); for (int k=1; k<=n; k++) bit[k]=0; for (int k=i; k>=j; k--) pos[k]=p++; for (int k=1; k<=n; k++){ if (a[k]>i) pos[a[k]]=p++; if (a[k]>=j) v.push_back(a[k]); } t=0; for (int k=1; k<v.size(); k++){ t+=qry(n)-qry(pos[v[k]]); upd(pos[v[k]]); } dp[i]=min(dp[i], dp[j-1]+t); } } cout << dp[n] << "\n"; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:33:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |             for (int k=1; k<v.size(); k++){
      |                           ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...