Submission #1078759

# Submission time Handle Problem Language Result Execution time Memory
1078759 2024-08-28T05:55:22 Z PoPularPlusPlus Closing Time (IOI23_closing) C++17
9 / 100
1000 ms 7400 KB
#include "closing.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define vf first
#define vs second

int max_score(int n, int x, int y, ll k,vector<int> u, vector<int> v, vector<int> w){
    ll weight[n];
    memset(weight,0,sizeof weight);
    for(int i = 0; i < n - 1; i++){
        if(u[i] > v[i]){
            swap(u[i] , v[i]);
        }
        weight[u[i]] = w[i];
    }

    for(int i = 0; i < n-1; i++){
        w[i] = weight[i];
    }

    ll cur = 0;
    int ans = 0;
    int cur_w[n];
    for(int i = x; i >= 0; i--){
        for(int j = y; j < n; j++){
            memset(cur_w,0,sizeof cur_w);
            ll rem = k;
            ll cur = 0;
            for(int tp = x; tp >= i; tp--){
                rem -= cur;
                cur_w[tp] = cur;
                if(tp > 0){
                    cur += w[tp-1];
                }
            }

            cur = 0;
            for(int tp = y; tp <= j; tp++){
                rem -= cur;
                cur_w[tp] = cur;
                cur += w[tp];
            }

            if(rem >= 0){
                int res = (x - i) + (j - y) + 2;
               // cout << res << ' ';
                int left = x + 1 , right = y - 1;
                ll cur_l = w[x] , cur_r = w[y-1];
                while(rem >= 0 && left < n && right >= 0){
                    if(right < 0 || (left < n && cur_l - cur_w[left] < cur_r - cur_w[right])){
                        if(rem - (max(0LL,cur_l - cur_w[left])) >= 0){
                            rem -= (max(0LL,cur_l - cur_w[left]));
                            cur_w[left] += (max(0LL,cur_l - cur_w[left]));
                            res++;
                            left++;
                            cur_l += w[left-1];
                        }
                        else break;
                    }
                    else {
                        if(rem - max(0LL, cur_r - cur_w[right]) >= 0){
                            rem -= max(0LL, cur_r - cur_w[right]);
                            cur_w[right] += max(0LL, cur_r - cur_w[right]);
                            res++;
                            right--;
                            cur_r += w[right];
                        }
                        else break;
                    }
                }
               // cout << i << ' ' << j << ' ' << res << ' ' << rem << ' ' << left << ' ' << right << '\n';
               // cout << i << ' ' << j << ' ' << res << ' ' << left << ' ' << right << "\n";
                ans = max(ans , res);
            }
        }
    }
    return ans;
}

Compilation message

closing.cpp: In function 'int max_score(int, int, int, long long int, std::vector<int>, std::vector<int>, std::vector<int>)':
closing.cpp:25:8: warning: unused variable 'cur' [-Wunused-variable]
   25 |     ll cur = 0;
      |        ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1062 ms 7400 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Incorrect 1 ms 348 KB 7th lines differ - on the 1st token, expected: '27', found: '26'
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Incorrect 1 ms 348 KB 7th lines differ - on the 1st token, expected: '27', found: '26'
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -