Submission #462513

# Submission time Handle Problem Language Result Execution time Memory
462513 2021-08-10T16:54:18 Z Mounir Snowball (JOI21_ho_t2) C++14
33 / 100
2500 ms 6732 KB
#include <bits/stdc++.h>
#define sz(x) (int)x.size()
#define chmin(x, v) x = min(x, v)
#define chmax(x, v) x = max(x, v)
#define all(x) x.begin(), x.end()
#define pb push_back
#define pii pair<long long, long long>
#define deb first
#define fin second
#define int long long
using namespace std;
 
const int N = 3e5;
const long long OO = 1e18;
pii inters[N];
int nBoules, nJours;
 
int getInstant(long long posInter, long long posBoule){
      long long delta = -(posBoule - posInter);
      int gauche = 0, droite = nJours + 1;
      while (droite > gauche){
            int mid = (gauche + droite)/2;
            if (inters[mid].deb <= delta && inters[mid].fin > delta)
                  droite = mid;
            else
                  gauche = mid + 1;
      }
      return gauche;
}

long long boules[N];
 
 
signed main(){ 
      ios::sync_with_stdio(false);
      cin.tie(nullptr);
      cout.tie(nullptr);
 
      cin >> nBoules >> nJours;
      for (int i = 0; i < nBoules; ++i)
            cin >> boules[i];
 
      long long posCur = 0;
      inters[0] = {0, -1};
      for (int iJour = 1; iJour <= nJours; ++iJour){
            long long delta; cin >> delta;
            posCur += delta;
            inters[iJour] = {min(inters[iJour - 1].deb, posCur), max(max(inters[iJour - 1].fin, posCur), 0ll)};
           // cout << "inter " << inters[iJour].deb << " " << inters[iJour].fin << endl;
      }

      for (int iBoule = 0; iBoule < nBoules; ++iBoule){
            long long gauche = boules[iBoule] + inters[nJours].deb, droite = boules[iBoule]; //Gauche
 
            while (droite > gauche){
                  int mid = floor((gauche + droite)/double(2));
              ///    cout << "dicho " << gauche << " " << droite << " " << mid << endl;
 
                  int moment = getInstant(mid, boules[iBoule]);

                  if (moment <= nJours && (iBoule == 0 || moment < getInstant(mid, boules[iBoule - 1])))
                        droite = mid;
                  else
                        gauche = mid + 1;
            }
 
            long long deb = gauche;
            gauche = boules[iBoule] - 1, droite = boules[iBoule] + inters[nJours].fin;
            while (droite > gauche){
                  int mid =  floor((gauche + droite)/double(2)) + 1;
                //  cout << "dicho " << gauche << " " << droite << " " << mid << endl;
                  //cout << getInstant(mid, boules[iBoule]) << endl << endl;
                  int moment = getInstant(mid, boules[iBoule]);

                  if (moment <= nJours && (iBoule == nBoules - 1 || moment < getInstant(mid, boules[iBoule + 1])))
                        gauche = mid;
                  else
                        droite = mid - 1;
            }
            
            cout << gauche - deb + 1 << endl;
        //    cout << couverts[iBoule].deb << " " << couverts[iBoule].fin << endl;
      }
      return 0;
 
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 3 ms 332 KB Output is correct
4 Correct 16 ms 384 KB Output is correct
5 Correct 14 ms 392 KB Output is correct
6 Correct 15 ms 408 KB Output is correct
7 Correct 11 ms 384 KB Output is correct
8 Correct 11 ms 384 KB Output is correct
9 Correct 10 ms 380 KB Output is correct
10 Correct 5 ms 332 KB Output is correct
11 Correct 5 ms 332 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 2 ms 204 KB Output is correct
15 Correct 19 ms 380 KB Output is correct
16 Correct 18 ms 388 KB Output is correct
17 Correct 11 ms 380 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 4 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 3 ms 332 KB Output is correct
4 Correct 16 ms 384 KB Output is correct
5 Correct 14 ms 392 KB Output is correct
6 Correct 15 ms 408 KB Output is correct
7 Correct 11 ms 384 KB Output is correct
8 Correct 11 ms 384 KB Output is correct
9 Correct 10 ms 380 KB Output is correct
10 Correct 5 ms 332 KB Output is correct
11 Correct 5 ms 332 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 2 ms 204 KB Output is correct
15 Correct 19 ms 380 KB Output is correct
16 Correct 18 ms 388 KB Output is correct
17 Correct 11 ms 380 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 4 ms 332 KB Output is correct
20 Correct 31 ms 3340 KB Output is correct
21 Correct 30 ms 3440 KB Output is correct
22 Correct 32 ms 3396 KB Output is correct
23 Correct 54 ms 3464 KB Output is correct
24 Correct 282 ms 3652 KB Output is correct
25 Correct 2441 ms 6680 KB Output is correct
26 Correct 2401 ms 6732 KB Output is correct
27 Correct 2291 ms 6320 KB Output is correct
28 Correct 2199 ms 6420 KB Output is correct
29 Correct 2062 ms 6216 KB Output is correct
30 Correct 1351 ms 5880 KB Output is correct
31 Correct 464 ms 5460 KB Output is correct
32 Correct 393 ms 5340 KB Output is correct
33 Correct 194 ms 836 KB Output is correct
34 Correct 2241 ms 6676 KB Output is correct
35 Correct 2223 ms 6388 KB Output is correct
36 Correct 2423 ms 6716 KB Output is correct
37 Correct 2318 ms 6360 KB Output is correct
38 Correct 2267 ms 6396 KB Output is correct
39 Correct 2274 ms 6380 KB Output is correct
40 Correct 1473 ms 6440 KB Output is correct
41 Execution timed out 2579 ms 3316 KB Time limit exceeded
42 Halted 0 ms 0 KB -