답안 #1070250

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1070250 2024-08-22T12:29:15 Z YassineBenYounes Sprinklers (CEOI24_sprinklers) C++17
3 / 100
2000 ms 2260 KB
#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

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);
      | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Correct
2 Correct 0 ms 604 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 604 KB Correct
2 Correct 23 ms 2004 KB Correct
3 Correct 0 ms 604 KB Correct
4 Correct 24 ms 2092 KB Correct
5 Correct 24 ms 2260 KB Correct
6 Correct 1 ms 604 KB Correct
7 Correct 0 ms 604 KB Correct
8 Correct 5 ms 1012 KB Correct
9 Correct 0 ms 600 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Correct
2 Execution timed out 2031 ms 2256 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Correct
2 Correct 0 ms 604 KB Correct
3 Correct 1 ms 600 KB Correct
4 Correct 1 ms 604 KB Correct
5 Incorrect 1 ms 456 KB User solution is worse than jury's solution
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Correct
2 Execution timed out 2041 ms 2256 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Correct
2 Correct 0 ms 604 KB Correct
3 Correct 23 ms 2004 KB Correct
4 Correct 0 ms 604 KB Correct
5 Correct 24 ms 2092 KB Correct
6 Correct 24 ms 2260 KB Correct
7 Correct 1 ms 604 KB Correct
8 Correct 0 ms 604 KB Correct
9 Correct 5 ms 1012 KB Correct
10 Correct 0 ms 600 KB Correct
11 Execution timed out 2031 ms 2256 KB Time limit exceeded
12 Halted 0 ms 0 KB -