Submission #965534

# Submission time Handle Problem Language Result Execution time Memory
965534 2024-04-18T19:40:55 Z MarwenElarbi Bitaro's travel (JOI23_travel) C++17
100 / 100
607 ms 7368 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define vi vector<int>
#define ve vector
#define ll long long
#define vl vector<ll>
#define vll vector<pair<ll,ll>>
#define onbit __builtin_popcount
#define ii pair<int,int>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 1e18
#define eps 1e-7
#define eps1 1e-2
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 1e5+5
using namespace std;
using namespace __gnu_pbds;
template <class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll MOD = (1LL << 61) - 1;
const int nax = 1e5+5;
const int MAX_VAL = 1e6+1;
double PI=3.14159265359;
int arx[8]={1,0,0,-1,-1,-1, 1, 1};
int ary[8]={0,1,-1, 0, 1,-1,-1, 1};
void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}
vector<int> tab(nax);
int main(){
    optimise;
    //setIO("dec");
    int n;
    cin>>n;
    tab.resize(n);
    for (int i = 0; i < n; ++i)
    {
        cin>>tab[i];
    }
    int q;
    cin>>q;
    while(q--){
        int s;
        cin>>s;
        int l=lower_bound(tab.begin(),tab.end(),s)-tab.begin();
        int r=l;
        //cout<<tab[l]<<endl;
        long long ans=0;
        while(true){
            //cout <<l<<" "<<r<<" "<<ans<<endl;
            if(l==0){
                ans+=tab[n-1]-s;
                break;
            }else if(r==n){
                ans+=s-tab[0];
                break;
            }
            if(s-tab[l-1]<=tab[r]-s){
                //cout << "nabba"<<endl;
                int i=lower_bound(tab.begin(),tab.end(),2*s-tab[r])-tab.begin();
                //cout <<tab[r]<<endl;
                ans+=s-tab[i];
                l=i;
                s=tab[i];
            }else{
                int i=lower_bound(tab.begin(),tab.end(),2*s-tab[l-1])-tab.begin()-1;
                //cout <<"nabba"<<" "<<2*s-tab[l-1]<<endl;
                ans+=tab[i]-s;
                r=i+1;
                s=tab[i];
            }
        }
        cout <<ans<<endl;
    }   
}

Compilation message

travel.cpp: In function 'void setIO(std::string)':
travel.cpp:36:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
travel.cpp:37:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 876 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 1 ms 876 KB Output is correct
8 Correct 1 ms 1112 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 0 ms 860 KB Output is correct
11 Correct 0 ms 860 KB Output is correct
12 Correct 1 ms 1112 KB Output is correct
13 Correct 1 ms 860 KB Output is correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 1 ms 860 KB Output is correct
16 Correct 1 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 876 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 1 ms 876 KB Output is correct
8 Correct 1 ms 1112 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 0 ms 860 KB Output is correct
11 Correct 0 ms 860 KB Output is correct
12 Correct 1 ms 1112 KB Output is correct
13 Correct 1 ms 860 KB Output is correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 1 ms 860 KB Output is correct
16 Correct 1 ms 860 KB Output is correct
17 Correct 19 ms 3024 KB Output is correct
18 Correct 16 ms 3028 KB Output is correct
19 Correct 16 ms 3028 KB Output is correct
20 Correct 18 ms 3028 KB Output is correct
21 Correct 15 ms 3028 KB Output is correct
22 Correct 15 ms 3156 KB Output is correct
23 Correct 15 ms 3028 KB Output is correct
24 Correct 15 ms 3024 KB Output is correct
25 Correct 16 ms 3028 KB Output is correct
26 Correct 16 ms 3028 KB Output is correct
27 Correct 15 ms 3028 KB Output is correct
28 Correct 16 ms 3136 KB Output is correct
29 Correct 15 ms 3136 KB Output is correct
30 Correct 16 ms 3040 KB Output is correct
31 Correct 15 ms 3028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 0 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 0 ms 860 KB Output is correct
5 Correct 0 ms 856 KB Output is correct
6 Correct 1 ms 856 KB Output is correct
7 Correct 549 ms 4976 KB Output is correct
8 Correct 546 ms 5320 KB Output is correct
9 Correct 552 ms 5064 KB Output is correct
10 Correct 556 ms 5052 KB Output is correct
11 Correct 570 ms 5640 KB Output is correct
12 Correct 554 ms 5468 KB Output is correct
13 Correct 255 ms 4668 KB Output is correct
14 Correct 238 ms 2384 KB Output is correct
15 Correct 430 ms 6180 KB Output is correct
16 Correct 440 ms 6600 KB Output is correct
17 Correct 432 ms 6092 KB Output is correct
18 Correct 260 ms 4456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 876 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 1 ms 876 KB Output is correct
8 Correct 1 ms 1112 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 0 ms 860 KB Output is correct
11 Correct 0 ms 860 KB Output is correct
12 Correct 1 ms 1112 KB Output is correct
13 Correct 1 ms 860 KB Output is correct
14 Correct 1 ms 860 KB Output is correct
15 Correct 1 ms 860 KB Output is correct
16 Correct 1 ms 860 KB Output is correct
17 Correct 19 ms 3024 KB Output is correct
18 Correct 16 ms 3028 KB Output is correct
19 Correct 16 ms 3028 KB Output is correct
20 Correct 18 ms 3028 KB Output is correct
21 Correct 15 ms 3028 KB Output is correct
22 Correct 15 ms 3156 KB Output is correct
23 Correct 15 ms 3028 KB Output is correct
24 Correct 15 ms 3024 KB Output is correct
25 Correct 16 ms 3028 KB Output is correct
26 Correct 16 ms 3028 KB Output is correct
27 Correct 15 ms 3028 KB Output is correct
28 Correct 16 ms 3136 KB Output is correct
29 Correct 15 ms 3136 KB Output is correct
30 Correct 16 ms 3040 KB Output is correct
31 Correct 15 ms 3028 KB Output is correct
32 Correct 1 ms 860 KB Output is correct
33 Correct 0 ms 860 KB Output is correct
34 Correct 1 ms 860 KB Output is correct
35 Correct 0 ms 860 KB Output is correct
36 Correct 0 ms 856 KB Output is correct
37 Correct 1 ms 856 KB Output is correct
38 Correct 549 ms 4976 KB Output is correct
39 Correct 546 ms 5320 KB Output is correct
40 Correct 552 ms 5064 KB Output is correct
41 Correct 556 ms 5052 KB Output is correct
42 Correct 570 ms 5640 KB Output is correct
43 Correct 554 ms 5468 KB Output is correct
44 Correct 255 ms 4668 KB Output is correct
45 Correct 238 ms 2384 KB Output is correct
46 Correct 430 ms 6180 KB Output is correct
47 Correct 440 ms 6600 KB Output is correct
48 Correct 432 ms 6092 KB Output is correct
49 Correct 260 ms 4456 KB Output is correct
50 Correct 549 ms 7364 KB Output is correct
51 Correct 489 ms 7236 KB Output is correct
52 Correct 457 ms 7216 KB Output is correct
53 Correct 607 ms 7368 KB Output is correct
54 Correct 603 ms 7316 KB Output is correct
55 Correct 597 ms 7224 KB Output is correct
56 Correct 271 ms 7108 KB Output is correct
57 Correct 270 ms 7108 KB Output is correct
58 Correct 272 ms 7164 KB Output is correct