Submission #1026942

# Submission time Handle Problem Language Result Execution time Memory
1026942 2024-07-18T14:24:50 Z nisanduu Mechanical Doll (IOI18_doll) C++14
Compilation error
0 ms 0 KB
#include "doll.h"
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
void create_circuit(int M, std::vector<int> A) {
  int N = A.size();
  ll inf = 1e9; 
  std::vector<int> C(M + 1,inf);
  vector<int> X,Y;
  map<int,int> mp;
  vector<int> unused;
  int sz = A.size();
  
  int crMinus = -1;
  C[0] = crMinus;
  Y.push_back(A[0]);
  X.push_back(crMinus);
  crMinus--;
  //A.push_back(0);
  int ind=1;
  
  for(int i=0;i<(A.size()-1);i++){
    //C[A[i]] = A[i+1];
    if(mp[A[i]]){
        int node = Y[mp[A[i]]];
        Y[mp[A[i]]] = A[i+1];
        X[mp[A[i]]] = node;
        continue;
    }
    C[A[i]] = crMinus;
    Y.push_back(A[i+1]);
    X.push_back(crMinus);
    mp[A[i]] = ind;
    ind++;
    crMinus--;
  }
  if(mp[A[sz-1]]){
      int node = Y[mp[A[i]]];
      Y[mp[A[i]]] = 0;
      X[mp[A[i]]] = node;
      //C[A[sz-1]]=0;
  }else{
     C[A[sz-1]]=0;
  }
  for(int i=0;i<(M+1);i++){
      if(C[i]==inf){
          unused.push_back(i);
      }
  }
  sz = unused.size();
  for(int i=0;i<(sz-1);i++){
      C[unused[i]] = unused[i+1];
  }
  if(sz>0){
      C[unused[sz-1]] = 0;
  }
  //std::vector<int> X(N), Y(N);
  answer(C, X, Y);
}

Compilation message

doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:23:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |   for(int i=0;i<(A.size()-1);i++){
      |               ~^~~~~~~~~~~~~
doll.cpp:39:25: error: 'i' was not declared in this scope
   39 |       int node = Y[mp[A[i]]];
      |                         ^
doll.cpp:7:7: warning: unused variable 'N' [-Wunused-variable]
    7 |   int N = A.size();
      |       ^