Submission #161094

# Submission time Handle Problem Language Result Execution time Memory
161094 2019-10-31T13:53:54 Z InfiniteJest Gondola (IOI14_gondola) C++14
60 / 100
24 ms 2404 KB
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <algorithm>
#include <math.h>
#include "gondola.h"
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
using namespace std;

ifstream in("input.txt");
ofstream out("output.txt");

int valid(int n, int inputSeq[]){
  int ans=1;
  bool pres[300001];
  for(int i=0;i<n;i++){
    if(inputSeq[i]<=n){
      int val=inputSeq[i];
      for(int y=0;y<n;y++){
        if((inputSeq[(i+y)%n]<=n&&inputSeq[(i+y)%n]!=val)/*||pres[inputSeq[(i+y)%n]]*/){
          ans=0;
          break;
        }
        val++;
        if(val==n+1)val=1;
        //pres[inputSeq[(i+y)%n]]=1;
      }
      break;
    }
  }
  for(int i=0;i<n;i++){
    if(pres[inputSeq[i]])ans=0;
    pres[inputSeq[i]]=1;
  }
  
  return ans;
}

int replacement(int n, int gondolaSeq[], int replacementSeq[]){
    bool flag=0;
    vector<pair<int,int> > p;
    int ind=-1,val;
    for(int i=0;i<n;i++){
      if(gondolaSeq[i]<=n){
        ind=i;
        val=gondolaSeq[i];
      }
      else flag=1;
    }
    if(!flag)return 0;
    if(ind==-1){
      ind=0;
      val=1;
    }
    for(int i=0;i<n;i++){
      if(gondolaSeq[(ind+i)%n]>n){
        flag=1;
        p.pb(mp(gondolaSeq[(ind+i)%n],val));
        //cout<<gondolaSeq[(ind+i)%n];
      }
      val++;
      if(val==n+1)val=1;
    }
    sort(p.begin(),p.end());
    int cur=n+1;
    int indtot=0;
    for(int i=0;i<p.size();i++){
      replacementSeq[indtot++]=p[i].se;
      for(;cur<p[i].fi;cur++)replacementSeq[indtot++]=cur;
      cur=p[i].fi+1;
    }
    //for(int i=0;i<indtot;i++)cout<<replacementSeq[i]<<" ";
    return indtot;
}

int countReplacement(int n, int inputSeq[]){
	  if(!valid(n,inputSeq))return 0;
  int tot=0;
  bool pres[300000];
  int mas=-1;
  for(int i=0;i<n;i++){
    if(inputSeq[i]>n){
      tot++;
      pres[inputSeq[i]]=1;
      mas=max(mas,inputSeq[i]);
    }
  }
  if(tot==0)return 1;
  int sol=1;
  for(int i=n+1;i<=mas;i++){
    if(pres[i]){
      if(tot==n)sol=(sol%mod*n%mod)%mod;
      tot--;
    }
    else{
      sol=(sol%mod*tot%mod)%mod;
    }
  }
  return sol;
}

Compilation message

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:72:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<p.size();i++){
                 ~^~~~~~~~~
gondola.cpp:66:10: warning: 'val' may be used uninitialized in this function [-Wmaybe-uninitialized]
       val++;
       ~~~^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 7 ms 632 KB Output is correct
7 Correct 14 ms 760 KB Output is correct
8 Correct 11 ms 760 KB Output is correct
9 Correct 6 ms 504 KB Output is correct
10 Correct 13 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 7 ms 504 KB Output is correct
7 Correct 14 ms 720 KB Output is correct
8 Correct 12 ms 764 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 13 ms 760 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 8 ms 760 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 15 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 11 ms 664 KB Output is correct
12 Correct 13 ms 760 KB Output is correct
13 Correct 18 ms 1404 KB Output is correct
14 Correct 11 ms 636 KB Output is correct
15 Correct 24 ms 2404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 420 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Incorrect 2 ms 376 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Incorrect 2 ms 464 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 296 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Incorrect 2 ms 376 KB Output isn't correct
8 Halted 0 ms 0 KB -