Submission #706467

#TimeUsernameProblemLanguageResultExecution timeMemory
706467Hacv16Gondola (IOI14_gondola)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;

const int MOD = 1e9 + 9;
const int INF = 0x3f3f3f3f;

int fexp(int b, int e){
    if(e == 0) return 1;
    if(e % 2 == 0) return fexp((b * b) % MOD, e >> 1);
    return (b * fexp(b, e - 1)) % MOD;
}

int valid(int n, int v[]){
    set<int> s(v, v + n);
    if((int) s.size() != n) return 0;

    for(int i = 0; i < n; i++){
        if(v[i] > n) continue;

        int left = (v[i] == 1 ? n : v[i] - 1), right = (v[i] == n ? 1 : v[i] + 1);

        int lefViz = (i == 0 ? v[n - 1] : v[i - 1]);
        int rigViz = (i == n - 1 ? v[0] : v[i + 1]);

        if((lefViz != left && lefViz <= n) || (rigViz != right && rigViz <= n)) return 0;
    }

    return 1;
}

int countReplacement(int n, int v[]){
    if(!valid(n, v)) return 0;

    set<ll> s;

    for(int i = 0; i < n; i++)
        if(v[i] > n) s.insert(v[i]);

    ll ans = (((int) s.size() != n) ? 1 : n);
    ll cnt = s.size(), cur = n + 1;

    for(auto x : s){
        ll exp = x - cur;
        ans = (ans * fexp(cnt, exp)) % MOD;
        cur = x + 1; cnt--;
    }

    return (int) cnt;
}

int replacement(int n, int v[], int answer[]){
    vector<int> order(n);
    vector<pair<int, int>> aux;

    int mn = INF, mnidx = 0;

    for(int i = 0; i < n; i++)
        if(v[i] < mn){ mn = v[i]; mnidx = i; }

    if(mn > n) mnidx = 0, mn = 1;

    for(int i = 0; i < n; i++){
        order[(i + mnidx) % n] = mn;
        mn = (mn == n ? 1 : mn + 1);
    }

    for(int i = 0; i < n; i++)
        if(v[i] > n) aux.push_back({v[i], order[i]});

    sort(aux.begin(), aux.end());

    int numOp = 0;

    for(int i = 0, val = n; i < aux.size(); i++){
        answer[numOp++] = aux[i].second; val++;

        while(val < aux[i].first)
            answer[numOp++] = val++;
    }

    return numOp;
}

Compilation message (stderr)

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:35:9: error: 'll' was not declared in this scope
   35 |     set<ll> s;
      |         ^~
gondola.cpp:35:11: error: template argument 1 is invalid
   35 |     set<ll> s;
      |           ^
gondola.cpp:35:11: error: template argument 2 is invalid
gondola.cpp:35:11: error: template argument 3 is invalid
gondola.cpp:38:24: error: request for member 'insert' in 's', which is of non-class type 'int'
   38 |         if(v[i] > n) s.insert(v[i]);
      |                        ^~~~~~
gondola.cpp:40:7: error: expected ';' before 'ans'
   40 |     ll ans = (((int) s.size() != n) ? 1 : n);
      |       ^~~~
      |       ;
gondola.cpp:41:7: error: expected ';' before 'cnt'
   41 |     ll cnt = s.size(), cur = n + 1;
      |       ^~~~
      |       ;
gondola.cpp:43:18: error: 'begin' was not declared in this scope
   43 |     for(auto x : s){
      |                  ^
gondola.cpp:43:18: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from gondola.cpp:1:
/usr/include/c++/10/valarray:1224:5: note:   'std::begin'
 1224 |     begin(const valarray<_Tp>& __va)
      |     ^~~~~
In file included from /usr/include/c++/10/filesystem:46,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from gondola.cpp:1:
/usr/include/c++/10/bits/fs_dir.h:549:3: note:   'std::filesystem::__cxx11::begin'
  549 |   begin(recursive_directory_iterator __iter) noexcept
      |   ^~~~~
gondola.cpp:43:18: error: 'end' was not declared in this scope
   43 |     for(auto x : s){
      |                  ^
gondola.cpp:43:18: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from gondola.cpp:1:
/usr/include/c++/10/valarray:1244:5: note:   'std::end'
 1244 |     end(const valarray<_Tp>& __va)
      |     ^~~
In file included from /usr/include/c++/10/filesystem:46,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:129,
                 from gondola.cpp:1:
/usr/include/c++/10/bits/fs_dir.h:554:3: note:   'std::filesystem::__cxx11::end'
  554 |   end(recursive_directory_iterator) noexcept
      |   ^~~
gondola.cpp:44:11: error: expected ';' before 'exp'
   44 |         ll exp = x - cur;
      |           ^~~~
      |           ;
gondola.cpp:45:9: error: 'ans' was not declared in this scope; did you mean 'abs'?
   45 |         ans = (ans * fexp(cnt, exp)) % MOD;
      |         ^~~
      |         abs
gondola.cpp:45:27: error: 'cnt' was not declared in this scope; did you mean 'int'?
   45 |         ans = (ans * fexp(cnt, exp)) % MOD;
      |                           ^~~
      |                           int
gondola.cpp:46:9: error: 'cur' was not declared in this scope
   46 |         cur = x + 1; cnt--;
      |         ^~~
gondola.cpp:49:18: error: 'cnt' was not declared in this scope; did you mean 'int'?
   49 |     return (int) cnt;
      |                  ^~~
      |                  int
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:75:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |     for(int i = 0, val = n; i < aux.size(); i++){
      |                             ~~^~~~~~~~~~~~