Submission #2454333


Source Code Expand

#include <iostream>
#include <vector>
using namespace std;

typedef pair<int, int> pairint;

bool pairCompare(const pairint& firstElof, const pairint& secondElof)
{
    return firstElof.second < secondElof.second;
}

int main() {
    int n,m;
    // n行m列
    cin >> n >> m;
    int x0, a, p;
    cin >> x0 >> a >> p;
    vector <pair<int, pairint> > g(n * m);
    int ans;
    // 成績を配列に格納
    int x = x0;
    for (int i = 0; i < n * m; i++) {
        // 成績
        g[i].first = x;
        x = (x + a) % p;
        // 座標
        g[i].second.first = i / m;
        g[i].second.second = i % m;
    }
    // 成績でソート
    sort(g.begin(), g.end());
    
    // 行ごとに処理
    vector <pairint> h(m);
    for (int i = 0; i < n; i++) {
        // 座標の取り出し
        for (int j = 0; j < m; j++) {
            h[j].first = g[i * m + j].second.first;
            h[j].second = g[i * m + j].second.second;
        }

        // 列でソート
        sort(h.begin(), h.end(), pairCompare);
       
        // i行目まで移動させる距離を合計
        for (int j = 0; j < m; j++) {
            int dist = abs(h[j].first - i) + abs(h[j].second - j);
            ans += dist;
        }
    }
    
    cout << ans;
    return 0;
}

Submission Info

Submission Time
Task C - 席替え
User fantasiabaetica
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1336 Byte
Status CE

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:31:28: error: ‘sort’ was not declared in this scope
     sort(g.begin(), g.end());
                            ^