답안 #667396

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
667396 2022-12-01T08:57:37 Z MohammadAghil Gap (APIO16_gap) C++17
100 / 100
66 ms 3236 KB
      #include <bits/stdc++.h>
#include "gap.h"
//   #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("avx2")
 using namespace std;
  typedef long long ll;
   typedef pair<ll, ll> pp;
     #define per(i,r,l) for(int i = (r); i >= (l); i--)
       #define rep(i,l,r) for(int i = (l); i < (r); i++)
          #define all(x) begin(x), end(x)
             #define sz(x) (int)(x).size()
                 #define pb push_back
                     #define ss second
                          #define ff first
                                  void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
void IOS(){
     cin.tie(0) -> sync_with_stdio(0);
     // #ifndef ONLINE_JUDGE
     //      #define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
     //      freopen("inp.txt", "r", stdin);
     //      freopen("out.txt", "w", stdout);
     // #else
     //      #define er(args ...) 0
     // #endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 1e9 + 9, maxn = 3e5 + 5, lg = 17, inf = ll(1e18) + 5, p = 9973;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll,md);return k*k%md*(b&1ll?a:1)%md;}
 
// ll a[maxn], n;

// void MinMax(ll s, ll t, ll &mn, ll &mx){
//      mn = mx = -1;
//      rep(i,0,n) {
//           if(a[i] >= s && a[i] <= t) {
//                if(mn == -1) mn = mx = a[i];
//                mn = min(mn, a[i]);
//                mx = max(mx, a[i]);
//           }
//      }
// }

ll findGap(int T, int N) {
     ll ans = 0;
     ll mn = 0, mx = inf;
     if(T == 1){
          N = (N + 1)>>1;
          vector<ll> a;
          while(mn <= mx && N--){
               MinMax(mn, mx, &mn, &mx);
               if(mn + 1){
                    a.pb(mn), a.pb(mx);
                    mn++, mx--;
               } else break;
          }
          sort(all(a));
          rep(i,1,sz(a)) ans = max(ans, a[i] - a[i-1]); 
     } else{
          MinMax(mn, mx, &mn, &mx);
          ll k = (mx - mn + N - 2)/(N - 1);
          ll cr = mn, X = mx;
          vector<ll> a;
          ans = k;
          while(cr < X){
               MinMax(cr, cr + k, &mn, &mx);
               if(mn + 1) a.pb(mn), a.pb(mx);
               cr += k + 1;
          }     
          sort(all(a));
          rep(i,1,sz(a)) ans = max(ans, a[i] - a[i-1]); 
     }
     return ans;
}

// int main(){ IOS();
//      int t = 1000;
//      while(t--){
//           n = rng()%10000 + 2;
//           ll ans = 0;
//           rep(i,0,n) {
//                a[i] = (i?a[i-1]:0) + rng()%10000 + 1;
//                if(i) ans = max(ans, a[i] - a[i-1]);
//           }
//           if(ans - findGap(1, n)){
//                rep(i,0,n) cout << a[i] << ' ';
//                cout << '\n';
//                return 0;
//           }
//      }
//      return 0;
// }
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 2 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 10 ms 888 KB Output is correct
17 Correct 10 ms 836 KB Output is correct
18 Correct 11 ms 804 KB Output is correct
19 Correct 10 ms 848 KB Output is correct
20 Correct 9 ms 860 KB Output is correct
21 Correct 40 ms 2184 KB Output is correct
22 Correct 40 ms 2212 KB Output is correct
23 Correct 48 ms 2148 KB Output is correct
24 Correct 40 ms 2160 KB Output is correct
25 Correct 44 ms 2180 KB Output is correct
26 Correct 41 ms 2240 KB Output is correct
27 Correct 38 ms 2152 KB Output is correct
28 Correct 39 ms 2152 KB Output is correct
29 Correct 47 ms 2212 KB Output is correct
30 Correct 41 ms 2244 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 13 ms 836 KB Output is correct
17 Correct 15 ms 820 KB Output is correct
18 Correct 12 ms 848 KB Output is correct
19 Correct 13 ms 848 KB Output is correct
20 Correct 6 ms 464 KB Output is correct
21 Correct 59 ms 2220 KB Output is correct
22 Correct 63 ms 2172 KB Output is correct
23 Correct 54 ms 2516 KB Output is correct
24 Correct 51 ms 2184 KB Output is correct
25 Correct 49 ms 3236 KB Output is correct
26 Correct 56 ms 2164 KB Output is correct
27 Correct 52 ms 2208 KB Output is correct
28 Correct 66 ms 2164 KB Output is correct
29 Correct 59 ms 2228 KB Output is correct
30 Correct 25 ms 1416 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 1 ms 208 KB Output is correct