Submission #1070250

#TimeUsernameProblemLanguageResultExecution timeMemory
1070250YassineBenYounesSprinklers (CEOI24_sprinklers)C++17
3 / 100
2041 ms2260 KiB
#include <bits/stdc++.h> using namespace std; void init(){ #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // ONLINE_JUDGE } typedef long long ll; #define vi vector<int> #define pii pair<int, int > #define vii vector<pii> #define ff first #define ss second #define pb push_back #define int ll const int mx = 1e5+5; int n, m; vi s, f; bool dp[mx][2]; bool check(int k){ memset(dp, 0, sizeof dp); if(f[0] < s[0]){ dp[0][0] = 0; } else{ dp[0][0] = 1; } int cur = s[0]-k; if(f[0] < cur)dp[0][1] = 0; else dp[0][1] = 1; for(int i = 1; i < n;i++){ /// go front bool worse = 0; for(int x : f){ if(x > s[i-1] && x < s[i]){worse=1;break;} } if(worse){ bool can = 1; for(int x : f){ if(x > (s[i-1]+k) && x < s[i]){can = 0;break;} } if(can){ dp[i][0] |= dp[i-1][0]; } else{ dp[i][0] = 0; } } else{ dp[i][0] |= dp[i-1][1]; dp[i][0] |= dp[i-1][0]; } //// go back worse = 0; for(int x : f){ if(x > s[i-1] && x < (s[i] - k)){worse=1;break;} } if(worse){ bool can = 1; for(int x : f){ if(x > (s[i-1]+k) && x < (s[i] - k)){can = 0;break;} } if(can){ dp[i][1] |= dp[i-1][0]; } else{ dp[i][1] = 0; } } else{ dp[i][1] |= dp[i-1][0]; dp[i][1] |= dp[i-1][1]; } } if(f[m-1] > s[n-1]){ if(f[m-1] > (s[n-1]+k))return 0; else{ return dp[n-1][0]; } } else{ return (dp[n-1][0] | dp[n-1][1]); } } string res; void construct(int k){ bool x = check(k); for(int i = 0; i < n;i++){ //cout << dp[i][0] << " " << dp[i][1] << endl; } for(int i = n-1; i >= 0;i--){ if(dp[i][0]){ res[i] = 'R'; } else{ res[i] = 'L'; } } } int32_t main(){ cin >> n >> m; for(int i = 0; i < n;i++){ int a;cin >> a; s.pb(a); } for(int i = 0; i < m;i++){ int a;cin >> a; f.pb(a); } int l = 0, r = 1e9; int ans = -1; while(l <= r){ int md = (l+r)/2; bool x = check(md); if(x){ ans = md; r = md-1; } else{ l = md+1; } } //int ans = 3; cout << ans << endl; if(ans != -1){ res.resize(n, ' '); construct(ans); cout << res << endl; } }

Compilation message (stderr)

Main.cpp: In function 'void construct(ll)':
Main.cpp:93:10: warning: unused variable 'x' [-Wunused-variable]
   93 |     bool x = check(k);
      |          ^
Main.cpp: In function 'void init()':
Main.cpp:6:8: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 | freopen("input.txt", "r", stdin);
      | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:7:8: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 | freopen("output.txt", "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...
#Verdict Execution timeMemoryGrader output
Fetching results...