結果

問題 No.2652 [Cherry 6th Tune N] Δρονε χιρχλινγ
ユーザー hitonanode
提出日時 2024-03-10 18:21:57
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 168 ms / 2,000 ms
コード長 924 bytes
コンパイル時間 2,667 ms
コンパイル使用メモリ 120,800 KB
実行使用メモリ 13,568 KB
最終ジャッジ日時 2024-09-29 21:43:51
合計ジャッジ時間 29,846 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

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

// 1000L
// N <= 2e5

// sqrt(N) で区切る?
// ブロック間移動: L / sqrt(N) * N
// ブロック内移動: L / sqrt(N) * N

void solve() {
    int N, L;
    cin >> N >> L;

    const int BS = ceil(sqrt(N));
    const int W = (L + 1 + BS - 1) / BS;

    vector is(BS, vector<vector<int>>(BS));

    vector<int> X(N), Y(N);
    for (int i = 0; i < N; ++i) {
        cin >> X.at(i) >> Y.at(i);
        is.at(X.at(i) / W).at(Y.at(i) / W).push_back(i);
    }

    cout << N << '\n';

    for (int i = 0; i < BS; ++i) {
        if (i % 2) reverse(is.at(i).begin(), is.at(i).end());
        for (auto v : is.at(i)) {
            for (auto j : v) cout << X.at(j) << ' ' << Y.at(j) << '\n';
        }
    }
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int T;
    cin >> T;
    while (T--) solve();
}
0