結果
| 問題 |
No.2339 Factorial Paths
|
| コンテスト | |
| ユーザー |
milanis48663220
|
| 提出日時 | 2023-06-02 23:34:37 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 31 ms / 2,000 ms |
| コード長 | 2,783 bytes |
| コンパイル時間 | 1,563 ms |
| コンパイル使用メモリ | 123,112 KB |
| 最終ジャッジ日時 | 2025-02-13 21:07:38 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
ソースコード
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
return vector<vector<T>>(n, vector<T>(m, v));
}
template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}
template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
if(v.empty()) {
cout << endl;
return;
}
for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
cout << v.back() << endl;
}
int f(int n){
static bool ok[500];
static int memo[500];
if(n == 1) return 1;
if(n == 2) return 2;
if(n == 3) return 3;
if(ok[n]) return memo[n];
int l = n/2;
int r = n-l;
memo[n] = r+1+f(l)+f(r);
ok[n] = true;
return memo[n];
}
vector<string> solve(int n){
static bool ok[500];
static vector<string> memo[500];
if(n == 1){
return {"."};
}
if(n == 2){
return {"..", ".."};
}
if(n == 3){
return {"...", "...", "..."};
}
if(ok[n]) return memo[n];
int l = n/2;
auto ans_l = solve(l);
int r = n-l;
auto ans_r = solve(r);
int h = l+1+ans_l.size()+ans_r.size();
int w = r+1+ans_l[0].size()+ans_r[0].size();
vector<string> ans(h, string(w, '#'));
for(int i = 0; i < l+1; i++){
for(int j = 0; j < r+1; j++){
ans[i][j] = '.';
}
}
int s = l+1, t = r+1;
ans[s][t-1] = '.';
for(int i = 0; i < ans_l.size(); i++){
for(int j = 0; j < ans_l[i].size(); j++){
ans[s+i][t+j] = ans_l[i][j];
}
}
s = l+1+ans_l.size(), t = r+1+ans_l[0].size();
ans[s][t-1] = '.';
for(int i = 0; i < ans_r.size(); i++){
for(int j = 0; j < ans_r[i].size(); j++){
ans[s+i][t+j] = ans_r[i][j];
}
}
memo[n] = ans;
ok[n] = true;
return memo[n];
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
int n; cin >> n;
auto ans = solve(n);
cout << ans.size() << ' ' << ans[0].size() << endl;
print_vector(ans, '\n');
}
milanis48663220