제출 #1260070

#제출 시각아이디문제언어결과실행 시간메모리
1260070minggaGroup Photo (JOI21_ho_t3)C++20
64 / 100
5094 ms268140 KiB
// Author: caption_mingle #include "bits/stdc++.h" using namespace std; #define ln "\n" #define pb push_back #define fi first #define se second #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define ll long long const int mod = 1e9 + 7; const int inf = 2e9; const int N = 5005; int n, a[N], pos[N], dp[N], g[N][N], l[N][N], psg[N][N], psl[N][N]; int cost(int i, int j) { int ans = 0; for(int k = i; k <= j; k++) { ans += g[k][j + 1] + l[k][i]; } // cerr << i << ' ' << j << ' ' << ans << ln; return ans; } signed main() { cin.tie(0) -> sync_with_stdio(0); #define task "" if(fopen(task ".INP", "r")) { freopen(task ".INP", "r", stdin); freopen(task ".OUT", "w", stdout); } cin >> n; for(int i = 1; i <= n; i++) { cin >> a[i], pos[a[i]] = i; } for(int i = 1; i <= n; i++) { for(int j = n; j >= i; j--) { g[i][j] = g[i][j + 1] + (pos[j] < pos[i]); psg[i][j] = psg[i - 1][j] + g[i][j]; } for(int j = i - 1; j > 0; j--) { l[i][j] = l[i][j + 1] + (pos[j] < pos[i]); psl[i][j] = psl[i - 1][j] + l[i][j]; } } for(int i = 1; i <= n; i++) { dp[i] = inf; for(int j = i; j > 0; j--) { dp[i] = min(dp[i], dp[j - 1] + cost(j, i)); } // for(int j = 1; j <= n; j++) { // cerr << i << ' ' << j << ' ' << g[i][j] << ' ' << l[i][j] << ln; // } } cout << dp[n]; cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC; }

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int main()':
Main.cpp:31:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |                 freopen(task ".INP", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:32:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |                 freopen(task ".OUT", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#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...