Submission #413369

#TimeUsernameProblemLanguageResultExecution timeMemory
413369ocarimaGroup Photo (JOI21_ho_t3)C++14
44 / 100
5058 ms332 KiB
#include<bits/stdc++.h> using namespace std; #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL) #define lli long long int #define vi vector<int> #define vlli vector<long long int> #define pii pair<int, int> #define plli pair<lli, lli> #define rep(i, a, b) for(lli i = (a); i <= (b); i++) #define repa(i, a, b) for(lli i = (a); i >= (b); i--) #define repv(x, v) for(auto x : v) #define debug(x) cout << #x << " = " << x << endl #define debugsl(x) cout << #x << " = " << x << ", " #define debugarr(x, a, b) cout << #x << " = ["; rep(ii, a, b) cout << x[ii] << ", "; cout << "]\n" #define pb push_back #define nl "\n" #define MAX_N 5002 #define INF (1ll << 62) lli n, h[MAX_N], dp[MAX_N]; lli costo(lli l, lli r){ vlli tmp; lli pos, cnt, offset; rep(i, 1, n) if (h[i] >= l) tmp.pb(h[i]); cnt = offset = 0; repa(i, r, l){ rep(j, 0, tmp.size() - 1) if (tmp[j] == i){ pos = j; break; } repa(j, pos, offset + 1){ swap(tmp[j], tmp[j - 1]); ++cnt; } ++offset; } return cnt; } int main() { fastio; cin >> n; rep(i, 1, n) cin >> h[i]; rep(i, 1, n){ dp[i] = INF; rep(j, 0, i - 1){ dp[i] = min(dp[i], dp[j] + costo(j + 1, i)); } } cout << dp[n]; return 0; }

Compilation message (stderr)

Main.cpp: In function 'long long int costo(long long int, long long int)':
Main.cpp:11:41: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 | #define rep(i, a, b) for(lli i = (a); i <= (b); i++)
      |                                         ^
Main.cpp:33:9: note: in expansion of macro 'rep'
   33 |         rep(j, 0, tmp.size() - 1) if (tmp[j] == i){ pos = j; break; }
      |         ^~~
Main.cpp:35:23: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   35 |             swap(tmp[j], tmp[j - 1]);
      |                       ^
#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...