Submission #962364

# Submission time Handle Problem Language Result Execution time Memory
962364 2024-04-13T11:19:23 Z IUA_Hasin Gondola (IOI14_gondola) C++17
75 / 100
17 ms 9564 KB
#include "gondola.h"
#include <bits/stdc++.h>
 
#define endl                                "\n"
#define yeap                                cout<<"YES"<<endl
#define nope                                cout<<"NO"<<endl
#define ll                                  long long

using namespace std;

const ll N = 1e6;
ll vis[N];
ll vec[N];

int valid(int n, int inputSeq[])
{
  ll mn = 300000;
  ll mx = -1;
  ll mnind = 0;
  ll status = 1;
  for(int i=0; i<n; i++){
    ll a = inputSeq[i];
    if(a<mn){
      mn = a;
      mnind = i;
    }
    mx = max(mx, a);
    vis[a]++;
    if(vis[a]>1){
      status = -1;
    }
  }

  if(status==-1){
    return 0;
  } else {
    if(mn>=n){
      return 1;
    } else {
      ll cnt = 0;
      ll ind = mnind;
      ll temp = mn;
      while(cnt<n){
        ll temp1 = ind%n;
        if(inputSeq[temp1]<=n){
          if(inputSeq[temp1]!=temp){
            status = -1;
            break;
          }
          cnt++;
          ind++;
          temp++;
        } else {
          cnt++;
          ind++;
          temp++;
        }
      }
      if(status==-1){
        return 0;
      } else {
        return 1;
      }
    }
  }



}

//----------------------

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{ 
  ll mx = -1;
  ll mn = 300000;
  for(int i=0; i<n; i++){
    ll a = gondolaSeq[i];
    vis[a] = 1;
    mx = max(mx, a);
    mn = min(mn, a);
  }

  if(mx==n){
    return 0;
  } else {
    if(mn>n){
      for(int i=0; i<n; i++){
        ll a = gondolaSeq[i];
        vec[a] = i+1;
      }

      ll cnt = 0;
      ll cnt1 = n;
      for(int i=n+1; i<=mx; i++){
        ll b = vec[i];
        if(vis[i]==1){
          replacementSeq[cnt] = b;
          cnt++;
          cnt1++;
          while(cnt1<i){
            replacementSeq[cnt] = cnt1;
            cnt++;
            cnt1++;
          }
        }
      }

      return cnt;

    } else {
      ll mnind;
      for(int i=0; i<n; i++){
        if(gondolaSeq[i]==mn){
          mnind = i;
          break;
        }
      }

      ll cntt = 0;
      ll temp1 = mn;
      ll temp2 = mnind;

      while(cntt<n){
        ll a = temp1%n;
        ll b = temp2%n;
        ll c = gondolaSeq[b];
        if(a==0){
          a = n;
        }
        vec[c] = a;
        temp1++;
        temp2++;
        cntt++;
      }

      ll cnt = 0;
      ll cnt1 = n;
      for(int i=n+1; i<=mx; i++){
        ll b = vec[i];
        if(vis[i]==1){
          replacementSeq[cnt] = b;
          cnt++;
          cnt1++;
          while(cnt1<i){
            replacementSeq[cnt] = cnt1;
            cnt++;
            cnt1++;
          }
        }
      }

      return cnt;
    }
  }
}

//----------------------

int countReplacement(int n, int inputSeq[])
{
  ll status = valid(n, inputSeq);
  if(status==0){
    return 0;
  } else {
    ll big_count = 0;
    ll small_count = 0;
    ll mn = 300000;
    int mx = -1;
    for(int i=0; i<n; i++){
      mx = max(mx, inputSeq[i]);
      if(inputSeq[i]>n){
        big_count++;
      }
    }
    if(mx==n){
      return 1;
    } else if(mx==n+1){
      return 1;
    } else if(mx==n+2){
      return 1;
    } else if(mx==n+3){
      if(vis[n+1]==1){
        return 1;
      } else {
        return 2;
      }
    } else {
      if(big_count==1){
        return 1;
      } else if(big_count==2){
        ll ans = 0;
        ll a;
        for(int i=n+1; i<=250; i++){
          if(vis[i]==1){
            a = i-n-1;
            break;
          }
        }
        ll M = 1000000009;
        ll b = 1;
        for(int i=0; i<a; i++){
          b = b*2;
          b = b%M;
        }
        return b;
      } else if(big_count==3){
        ll ans = 0;
        ll tt = 0;
        ll a, b;
        ll temp;
        for(int i=n+1; i<=250; i++){
          if(vis[i]==1){
            if(tt==0){
              a = i-n-1;
              tt++;
              temp = i;
              // cout<<i<<endl;
            } else {
              b = i-temp-1;
              // cout<<i<<endl;
              break;
            }
          }
        }
        long long int M = 1000000009;
        ll c = 1;
        ll d = 1;
        for(int i=0; i<a; i++){
          c = c*3;
          c = c%M;
        }
        for(int i=0; i<b; i++){
          d = d*2;
          d = d%M;
        }
        // cout<<a<<" "<<b<<endl;
        // cout<<c<<" "<<d<<endl;
        ans = c*d;
        ans = ans%M;
        return ans;
      } else {
        sort(inputSeq, inputSeq+n);
        vector<pair<ll, ll>> v;
        ll pp = big_count;
        ll temp = n+1;
        for(int i=0; i<n; i++){
          ll a = inputSeq[i];
          if(a>n){
            v.push_back({a-temp, pp});
            pp--;
            temp = a+1;
          }
        }
        // for(int i=0; i<v.size(); i++){
        //   cout << v[i].first << " " << v[i].second << endl;
        // }

        vector<long long int> v1;
        ll M = 1000000009;
        for(int i=0; i<v.size(); i++){
          ll a = v[i].first;
          ll b = v[i].second;
          ll c = 1;
          for(int i=0; i<a; i++){
            c = c*b;
            c = c%M;
          }
          v1.push_back(c);
        }
        long long int ans = 1;
        for(int i=0; i<v1.size(); i++){
          ll temp1, temp2;
          if(ans>500000004){
            temp1 = ans-M;
          } else {
            temp1 = ans;
          }
          if(v1[i]>100000000){
            temp2 = v1[i]-M;
          } else {
            temp2 = v1[i];
          }
          ans = ((temp1%M)*(temp2%M))%M;
          ans = ans%M;
          // ans = ans%M;
          // v1[i] = v1[i]%M;
          // ans = ans*v1[i];
          // ans = ans%M;
        }
        if(ans<0){
          ans = ans+M;
        }
        return ans;
      }
    }
  }
}

Compilation message

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:192:12: warning: unused variable 'ans' [-Wunused-variable]
  192 |         ll ans = 0;
      |            ^~~
gondola.cpp:261:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  261 |         for(int i=0; i<v.size(); i++){
      |                      ~^~~~~~~~~
gondola.cpp:272:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  272 |         for(int i=0; i<v1.size(); i++){
      |                      ~^~~~~~~~~~
gondola.cpp:167:8: warning: unused variable 'small_count' [-Wunused-variable]
  167 |     ll small_count = 0;
      |        ^~~~~~~~~~~
gondola.cpp:168:8: warning: unused variable 'mn' [-Wunused-variable]
  168 |     ll mn = 300000;
      |        ^~
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:112:10: warning: 'mnind' may be used uninitialized in this function [-Wmaybe-uninitialized]
  112 |       ll mnind;
      |          ^~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:210:12: warning: 'a' may be used uninitialized in this function [-Wmaybe-uninitialized]
  210 |         ll a, b;
      |            ^
gondola.cpp:210:15: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
  210 |         ll a, b;
      |               ^
gondola.cpp:193:12: warning: 'a' may be used uninitialized in this function [-Wmaybe-uninitialized]
  193 |         ll a;
      |            ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 3 ms 776 KB Output is correct
7 Correct 7 ms 1372 KB Output is correct
8 Correct 6 ms 1116 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 7 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 3 ms 860 KB Output is correct
7 Correct 7 ms 1624 KB Output is correct
8 Correct 6 ms 1116 KB Output is correct
9 Correct 3 ms 604 KB Output is correct
10 Correct 7 ms 1372 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 4 ms 2136 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 7 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4456 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4640 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4548 KB Output is correct
11 Correct 7 ms 4696 KB Output is correct
12 Correct 7 ms 4700 KB Output is correct
13 Correct 10 ms 9308 KB Output is correct
14 Correct 7 ms 4696 KB Output is correct
15 Correct 17 ms 9564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 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 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 13 ms 4048 KB Output is correct
10 Correct 11 ms 3280 KB Output is correct
11 Correct 5 ms 2512 KB Output is correct
12 Correct 6 ms 2260 KB Output is correct
13 Incorrect 2 ms 860 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 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 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 436 KB Output is correct
9 Correct 13 ms 4076 KB Output is correct
10 Correct 11 ms 3280 KB Output is correct
11 Correct 6 ms 2512 KB Output is correct
12 Correct 6 ms 2260 KB Output is correct
13 Incorrect 2 ms 860 KB Output isn't correct
14 Halted 0 ms 0 KB -