結果

問題 No.2143 Only One Bracket
ユーザー cpbm_pcpbm_p
提出日時 2022-11-05 12:02:00
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 5,430 bytes
コンパイル時間 3,850 ms
コンパイル使用メモリ 233,552 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-26 11:46:36
合計ジャッジ時間 4,713 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #ifndef LOCAL
    #pragma GCC optimize("Ofast")
    #pragma GCC target("avx2")
    #pragma GCC optimize("unroll-loops")
    // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,fma,abm,mmx,avx,avx2,avx512f")
    #include <bits/stdc++.h>
// #else
    // #include <stdc++.h>
// #endif
using namespace std;
using ll = long long;
using ld = long double;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T,U>;
template<class T> using max_heap = priority_queue<T>;
template<class T> using min_heap = priority_queue<T,vector<T>,greater<T>>;
#define OVERLOADER(_1,_2,_3,NAME,...) NAME
#define REP2(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) REP2(i,0,n)
#define rep(...) OVERLOADER(__VA_ARGS__,REP2,REP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
template<class T, class U> inline bool chmin(T &a, U b) { if(a>b) {a=b; return 1;} return 0;}
template<class T, class U> inline bool chmax(T &a, U b) { if(a<b) {a=b; return 1;} return 0;}
ll max (ll lhs, ll rhs) {return std::max<ll>(lhs, rhs);}
ll min (ll lhs, ll rhs) {return std::min<ll>(lhs, rhs);}
template<class T>void uniqify(V<T>& v){v.erase(unique(ALL(v)),v.end());}
template<class T>V<T> compress(V<T>& v){V<T>vals=v;sort(ALL(vals));uniqify(vals);rep(i,v.size())v[i]=lower_bound(ALL(vals),v[i])-vals.begin();return vals;}
template<class T>V<T> sum_array(V<T>& v) {int n=v.size(); V<T> sum(n+1); rep(i,n) sum[i+1]=sum[i]+v[i]; return sum;}
// inputs
template<class T,class U> istream& operator>>(istream& is,P<T,U>&p){return is>>p.first>>p.second;}
template<class T> istream& operator>>(istream& is,V<T>&v){for(T& e:v) is>>e; return is;}
// outputs
template<class T,class U> ostream& operator<<(ostream& os,P<T,U>& p){return os<<p.first<<' '<<p.second;}
template<class T> ostream& operator<<(ostream& os,set<T>& v) {os<<'{';for(auto&l:v){os<<l<<", ";}os<<'}';return os;}
template<class T,class U> ostream& operator<<(ostream& os,map<T,U>& m){os<<'{';for(auto&p:m) {os<<p.first<<':'<<p.second<<'\n';}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os,V<T>& v) {int ss=v.size(); rep(ii,ss) {os<<v[ii]<<(ii+1==ss?"":" ");} return os;}
template<class T>inline void drop(T&& x) { cout << x << endl; exit(0); }
constexpr char ENDL = '\n';
inline void yesno(bool f) { cout << (f ? "Yes" : "No") << ENDL; }
constexpr ll INF = (1LL<<30)-1; // 問題毎にfit
constexpr ll INFLL = (1LL<<62)-1; // 問題毎にfit
const ld PI = acos(static_cast<long double>(-1));
constexpr int dy[]={0, 1, 0, -1};
constexpr int dx[]={1, 0, -1, 0};
// constexpr int dy[]={0, 1, 1, 1, 0, -1, -1, -1};
// constexpr int dx[]={1, 1, 0, -1, -1, -1, 0, 1};
struct IO_Setting{IO_Setting(){cin.tie(nullptr);ios_base::sync_with_stdio(false);cout<<fixed<<setprecision(15);cerr<<fixed<<setprecision(3);}}io_setting;

//  ---------- ac-library ---------- insert '/' into the head of the line below to enable
/*
#include <atcoder/all>   // ac-library
using namespace atcoder; // ac-library
std::ostream &operator<<(std::ostream &os, const modint998244353 &a) {return os<<a.val();}
std::ostream &operator<<(std::ostream &os, const modint1000000007 &a) {return os<<a.val();}
//*/
#ifdef LOCAL
    void debug_out() { cerr << endl; }
    template <class Head, class... Tail> void debug_out(Head H, Tail... T) { cerr << ", " << H; debug_out(T...); }
    #define debug(...) cerr << "Line " << __LINE__ << " : " << #__VA_ARGS__ << " ,,", debug_out(__VA_ARGS__)
#else
    #define debug(...) (void(0))
#endif
// using mint = modint1000000007;
// using mint = modint998244353;

int get() {
    string str;
    getline(cin, str);
    assert(str.length()==1);
    int n = stoi(str);
    assert(2 <= n && n <= 8);
    return n;
}

void naive() {
    // int n = 3;
    V<int> v = {-1,-1,-1,1,1,1};
    do {    
        {
        int s = 0, ok = 1;
        rep(i, 6) {
            s += v[i];
            if(s < 0) ok = 0;
        }
        if(!ok) continue;
        }

        rep(r1, 1, 5) {
            rep(r2, 2, 6) {
                // 切り方
                V<V<int>> tmp(3);
                rep(t, 0, r1) tmp[0].push_back(v[t]);
                rep(t, r1, r2) tmp[1].push_back(v[t]);
                rep(t, r2, 6) tmp[2].push_back(v[t]);

                if(tmp[0]==tmp[1] || tmp[0]==tmp[2] || tmp[1]==tmp[2]) continue;

                sort(ALL(tmp));
                int okcnt = 0;

                do {
                    bool ok = 1;
                    V<int> hoge;
                    for(auto ii:tmp[0]) hoge.push_back(ii);
                    for(auto ii:tmp[1]) hoge.push_back(ii);
                    for(auto ii:tmp[2]) hoge.push_back(ii);

                    int sum = 0;
                    rep(i, 6) {
                        sum += hoge[i];
                        if(sum < 0) ok = 0;
                    }
                    if(ok) okcnt+=1;
                } while(next_permutation(ALL(tmp)));

                if(okcnt==1) {
                    debug(v);
                    rep(i, 3) debug(i, tmp[i]);
                }
            }
        }
    } while(next_permutation(ALL(v)));
}

int main() {
    int n = get();
    rep(i, n) {
        if(i==0) {
            rep(j, n-1) cout << '(';
            cout << endl;
        }
        else {
            rep(j, n-i) cout << ')';
            rep(j, n-i-1) cout << '(';
            cout << endl;
        }
    }
}
0