結果

問題 No.2339 Factorial Paths
ユーザー milanis48663220milanis48663220
提出日時 2023-06-02 23:34:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 2,783 bytes
コンパイル時間 1,913 ms
コンパイル使用メモリ 126,716 KB
実行使用メモリ 18,380 KB
最終ジャッジ日時 2023-08-28 06:15:07
合計ジャッジ時間 8,929 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 4 ms
4,620 KB
testcase_14 AC 5 ms
5,408 KB
testcase_15 AC 12 ms
10,200 KB
testcase_16 AC 16 ms
13,280 KB
testcase_17 AC 19 ms
15,780 KB
testcase_18 AC 21 ms
17,012 KB
testcase_19 AC 22 ms
18,068 KB
testcase_20 AC 21 ms
17,240 KB
testcase_21 AC 23 ms
18,380 KB
testcase_22 AC 21 ms
17,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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');
}
0