Submission #1308585

#TimeUsernameProblemLanguageResultExecution timeMemory
1308585nvc2k8Collecting Stamps 3 (JOI20_ho_t3)C++20
5 / 100
48 ms52460 KiB
#include <bits/stdc++.h> #define TASK "stamp" #define endl mmm #define mp make_pair #define pb push_back #define fi first #define se second #define BIT(i,x) (((i)>>(x))&1) #define FOR(i,a,b) for(int i = (a); i<=(b); i++) #define FORD(i,a,b) for(int i = (a); i>=(b); i--) #define all(C) (C).begin(), (C).end() using namespace std; using ll = long long; using pii = pair<int,int>; const int INT_LIM = 2147483647; const ll LL_LIM = 9223372036854775807; template <typename X> bool minimize(X &x, const X &y) {if (x>y){x = y; return true;}return false;} template <typename X> bool maximize(X &x, const X &y) {if (x<y){x = y; return true;}return false;} ///------------------------------------------/// const int maxn = 205; int n, L; int a[maxn]; int b[maxn]; void inp() { cin >> n >> L; FOR(i, 1, n) cin >> a[i]; FOR(i, 1, n) cin >> b[i]; } int f[maxn][maxn][maxn][2]; int ans = 0; int dist(int x, int y) { if (x>y) swap(x,y); return min(y-x, L-y+x-1); } void solve() { FOR(i, 1, n) FOR(j, 1, n) FOR(c, 0, n) FOR(dir, 0, 1) f[i][j][c][dir] = INT_LIM; f[1][1][a[1]<=b[1]][0] = f[1][1][a[1]<=b[1]][1] = a[1]; minimize(f[n][n][L-a[n]<=b[n]][0], L-a[n]); minimize(f[n][n][L-a[n]<=b[n]][1], L-a[n]); FOR(gap, 0, n-1) FOR(l, 1, n) { int r = (l+gap-1)%n+1; FOR(c, 0, n) FOR(dir, 0, 1) if (f[l][r][c][dir]!=INT_LIM) { maximize(ans, c); // cout << l << ' ' << r << ' ' << c << ' ' << dir << ' ' << f[l][r][c][dir] << '\n'; if (gap==n-1) continue; int s = ((dir==0)?l:r); int newR = r%n+1; int tmp = f[l][r][c][dir]+dist(a[s], a[newR]); minimize(f[l][newR][c+(tmp<=b[newR])][1], tmp); int newL = (l-2+n)%n+1; tmp = f[l][r][c][dir]+dist(a[s], a[newL]); minimize(f[newL][r][c+(tmp<=b[newL])][0], tmp); } } cout << ans << '\n'; } signed main() { ///--------------------------/// ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); if (fopen(TASK".INP","r")!=NULL) { freopen(TASK".INP","r",stdin); freopen(TASK".OUT","w",stdout); } ///--------------------------/// int NTEST = 1; bool multitest = 0; if (multitest) cin >> NTEST; while (NTEST--) { inp(); solve(); } return 0; } ///------------------------------------------///

Compilation message (stderr)

ho_t3.cpp: In function 'int main()':
ho_t3.cpp:75:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |         freopen(TASK".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
ho_t3.cpp:76:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |         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...