Submission #1045370

# Submission time Handle Problem Language Result Execution time Memory
1045370 2024-08-05T21:17:42 Z Trent The Big Prize (IOI17_prize) C++17
Compilation error
0 ms 0 KB
#include "bits/stdc++.h"
using namespace std;

#define forR(i, x) for(int i = 0; i < (x); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) x.begin(), x.end()
struct pii{int a, b;};
typedef vector<int> vi;
typedef set<int> si;
typedef vector<bool> vb;
typedef vector<vector<pii>> aList;
typedef long long ll;

long long minimum_walk(std::vector<int> p, int s) {
    int n = p.size();
    vector<pii> cy;
    vb vis(n);
    ll tot = 0;
    forR(i, n) {
        if(!vis[i]) {
            vector<int> els = {i};
            for(int pre=i, j = p[i]; j != i; pre=j, j = p[j]) {
                assert(!vis[j]);
                els.push_back(j);
            }
            for(int j : els) {
                assert(!vis[j]);
                vis[j] = true;
            }
            // for(int j : els) cout << j << ' ';
            // cout << '\n';
            if(els.size() > 1) {
                cy.push_back({els[0], els[0]});
                for(int j : els) {
                    cy.back().a = min(cy.back().a, j);
                    cy.back().b = max(cy.back().b, j);
                }
                REP(ci, 1, els.size()) tot += abs(els[ci] - els[ci-1]);
                tot += abs(els.front() - els.back());
            }
        }
    }
    // cout << cy.size() << '\n';
    sort(all(cy), [](pii a, pii b){return a.a < b.a;});
    int rch = 0;
    for(auto [a, b] : cy) {
        if(a > rch) tot += 2 * (a - rch);
        rch = max(rch, b);
    }
    return tot;
}

Compilation message

prize.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
prize.cpp:22:21: warning: variable 'pre' set but not used [-Wunused-but-set-variable]
   22 |             for(int pre=i, j = p[i]; j != i; pre=j, j = p[j]) {
      |                     ^~~
prize.cpp:5:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 | #define REP(i, a, b) for(int i = (a); i < (b); ++i)
      |                                         ^
prize.cpp:38:17: note: in expansion of macro 'REP'
   38 |                 REP(ci, 1, els.size()) tot += abs(els[ci] - els[ci-1]);
      |                 ^~~
/usr/bin/ld: /tmp/ccTImP5u.o: in function `main':
grader.cpp:(.text.startup+0x98): undefined reference to `find_best(int)'
collect2: error: ld returned 1 exit status