제출 #612424

#제출 시각아이디문제언어결과실행 시간메모리
612424yuto1115정렬하기 (IOI15_sorting)C++17
74 / 100
1041 ms15908 KiB
#include "sorting.h"
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, s, n) for(ll i = ll(s); i < ll(n); ++i)
#define rrep(i, n) for(ll i = ll(n)-1; i >= 0; --i)
#define rrep2(i, n, t) for(ll i = ll(n)-1; i >= ll(t); --i)
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(),a.end()
#define SZ(a) int(a.size())
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<P>;
using vvp = vector<vp>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vs = vector<string>;
const int inf = 1001001001;
const ll linf = 1001001001001001001;

template<class T>
bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int findSwapPairs(int n, int s[], int m, int x[], int y[], int p[], int q[]) {
    vi to(n);
    iota(all(to), 0);
    vi rev(n);
    iota(all(rev), 0);
    rep(i, m + 1) {
//        cerr << i << endl;
//        rep(j, n) cerr << to[j] << ' ' << rev[j] << endl;
        vvi ls;
        vb seen(n);
        rep(j, n) {
            if (seen[j]) continue;
            ls.pb({});
            int now = j;
            while (true) {
                seen[now] = true;
                ls.back().pb(now);
                int nx = s[rev[now]];
                if (seen[nx]) break;
                now = nx;
            }
        }
        if (n - SZ(ls) > i) {
            swap(to[rev[x[i]]], to[rev[y[i]]]);
            swap(rev[x[i]], rev[y[i]]);
            continue;
        }
        vp ev;
        for (const vi &v: ls) {
            rep2(j, 1, SZ(v)) ev.eb(v[0], v[j]);
        }
        rep(j, i) {
            swap(rev[to[x[j]]], rev[to[y[j]]]);
            swap(to[x[j]], to[y[j]]);
            if (j < SZ(ev)) {
                p[j] = rev[ev[j].first];
                q[j] = rev[ev[j].second];
            } else {
                p[j] = q[j] = 0;
            }
        }
        return i;
    }
    assert(false);
}

컴파일 시 표준 에러 (stderr) 메시지

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:57:23: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   57 |             int now = j;
      |                       ^
sorting.cpp:85:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   85 |         return i;
      |                ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...