結果

問題 No.2449 square_permutation
ユーザー askr58
提出日時 2026-08-06 17:28:51
言語 C++23
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 210 ms / 2,000 ms
+ 546µs
コード長 571 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,394 ms
コンパイル使用メモリ 199,572 KB
実行使用メモリ 24,832 KB
最終ジャッジ日時 2026-08-06 17:28:59
合計ジャッジ時間 6,662 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <map>
#include <ranges>
#include <algorithm>
#include <vector>
using namespace std;
using ll=long long;
int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	map<int,vector<int>> mp;
	for(int i=1;i<=n;i++){
		int x=i;
		for(int j=2;j*j<=x;j++){
			while(x%(j*j)==0){
				x/=(j*j);
			}
		}
		mp[x].push_back(i);
	}
	vector<int> ans(n+1);
	for(auto[key,vec]:mp){
		ranges::sort(vec,greater{});
		for(int i=0;i<vec.size();i++)ans[vec[i]]=vec[vec.size()-1-i];
	}
	for(int i=1;i<=n;i++)cout<<ans[i]<<(i==n?"\n":" ");
}


0