Submission #397694

#TimeUsernameProblemLanguageResultExecution timeMemory
397694ChrisTGroup Photo (JOI21_ho_t3)C++17
0 / 100
1 ms332 KiB
#include <bits/stdc++.h> using namespace std; const int MN = 5e3 + 5; int dp[MN], f[MN][MN], a[MN], stopAt[MN]; int main () { int n; scanf ("%d",&n); for (int i = 1; i <= n; i++) scanf ("%d",&a[i]); for (int i = 1; i <= n; i++) { for (int j = i+1; j <= n; j++) { if (a[i] < a[j]) { f[1][a[j]]++; f[a[i]+1][a[j]]--; } else { f[a[j]+1][1]++; f[a[i]+1][1]--; } } } for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) f[i][j] += f[i-1][j] + f[i][j-1] - f[i-1][j-1]; for (int i = 1; i <= n; i++) { dp[i] = 1e9; for (int j = i; j >= 1; j--) dp[i] = min(dp[i],dp[j-1]+f[j][i]); } printf ("%d\n",dp[n]); return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:6:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    6 |  int n; scanf ("%d",&n);
      |         ~~~~~~^~~~~~~~~
Main.cpp:7:37: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    7 |  for (int i = 1; i <= n; i++) scanf ("%d",&a[i]);
      |                               ~~~~~~^~~~~~~~~~~~
#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...