結果

問題 No.3726 Flawless Flow
コンテスト
ユーザー cho435
提出日時 2026-09-19 18:12:07
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 9 ms / 2,000 ms
+ 534µs
コード長 1,367 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,017 ms
コンパイル使用メモリ 340,448 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2026-09-19 18:12:14
合計ジャッジ時間 5,521 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 59
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define rep(i, s, t) for (ll i = s; i < (ll)(t); i++)
#define all(x) begin(x), end(x)
template <class T> bool chmin(T& x, T y) {
	return x > y ? (x = y, true) : false;
}
template <class T> bool chmax(T& x, T y) {
	return x < y ? (x = y, true) : false;
}

mt19937 mt(random_device{}());

void solve() {
	int n = 6;
	cin >> n;
	vector<int> a(n), b(n);

	// iota(all(a), 0);
	// iota(all(b), 0);
	// shuffle(all(a), mt);

	// cout << " --- start --- " << endl;
	// rep(i, 0, n) cout << a[i] + 1 << ' ';
	// cout << endl;
	// rep(i, 0, n) cout << b[i] + 1 << ' ';
	// cout << endl;
	// cout << " --- " << endl;

	rep(i, 0, n) cin >> a[i], a[i]--;
	rep(i, 0, n) cin >> b[i], b[i]--;

	vector<int> p(n);
	rep(i, 0, n) p[b[i]] = i;

	vector<vector<int>> ans(n + 1);
	ans[0] = a;
	rep(lp, 0, n) {
		for (int i = lp & 1; i < n - 1; i += 2) {
			if (p[a[i]] > p[a[i + 1]]) {
				swap(a[i], a[i + 1]);
			}
		}
		ans[lp + 1] = a;
	}
	// vector<vector<int>> ans(n, vector<int>(n, 0));

	// rep(i, 0, n) ans[i][n - 1 - i] = 1;
	// rep(i, 0, n - 1) ans[i + 1][n - 1 - i] = 1;

	rep(i, 0, n + 1) {
		rep(j, 0, n) cout << ans[i][j] + 1 << ' ';
		cout << '\n';
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(15);
	int t = 1;
	// cin >> t;
	while (t--) solve();
}
0