結果
| 問題 |
No.1988 Divisor Tiling
|
| コンテスト | |
| ユーザー |
Nachia
|
| 提出日時 | 2024-04-26 18:16:11 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 1,023 bytes |
| コンパイル時間 | 859 ms |
| コンパイル使用メモリ | 80,900 KB |
| 最終ジャッジ日時 | 2025-02-21 09:09:23 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 32 |
ソースコード
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
vector<vector<int>> solve(int n, int h){
vector<int> ansFlat(n);
int p1 = 0, p2 = n;
for(int d=1; n%d==0; d*=2){
int D = n / d;
if(d != 1) rep(i,D) ansFlat[p1++] = D;
rep(i,d) ansFlat[--p2] = d;
}
vector<vector<int>> ans(h, vector<int>(n/h));
rep(y,h) rep(x,n/h) ans[y][x] = ansFlat[y*(n/h)+x];
return ans;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N; cin >> N;
int H; cin >> H;
int W = N / H;
vector<vector<int>> ans;
if(H == (H & -H)){
ans = solve(N, H);
}
else{
vector<vector<int>> buf = solve(N, W);
ans.assign(H, vector<int>(W));
rep(y,H) rep(x,W) ans[y][x] = buf[x][y];
}
rep(y,H){
rep(x,W){
if(x) cout << ' ';
cout << ans[y][x];
}
cout << '\n';
}
return 0;
}
Nachia