結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー codershifthcodershifth
提出日時 2015-10-12 10:11:09
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,168 bytes
コンパイル時間 1,317 ms
コンパイル使用メモリ 152,280 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-28 12:37:48
合計ジャッジ時間 2,103 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int (i)=(a);i<(int)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define RANGE(vec) (vec).begin(),(vec).end()

using namespace std;


class TrendAndCountermeasures_PineDecorationSequence1 {
public:
    void solve(void) {
            int T;
            cin>>T;
            // O(T*N^2)
            REP(t,T)
            {
                int N;
                cin>>N;
                using DecPine = vector<int>;
                //typedef array<int,3> DecPine;
                vector<DecPine> dec_pines;
                REP(i,N)
                {
                    int n = dec_pines.size();
                    int l,j;
                    bool update = false;
                    cin>>l;
                    for (j = 0; j < n; ++j)
                    {
                        auto &x = dec_pines[j];
                        // 同じ高さになってしまう
                        if ( any_of(RANGE(x),[l](int y){return y == l;}) )
                            continue;
                        // すでに門松ができている
                        if ( all_of(RANGE(x),[l](int y){return y > 0;}) )
                            continue;
                        REP(k,3)
                        {
                            if (x[k] > 0)
                                continue;
                            x[k] = l;
                            break;
                        }
                        update = true;
                        break;
                    }
                    if (!update)
                        dec_pines.push_back({l,-1,-1});
                }
                int cnt = 0;
                for (auto x : dec_pines)
                {
                    if (all_of(RANGE(x),[](int y){return y > 0;}))
                        ++cnt;
                }
                cout<<cnt<<endl;
            }
    }
};

#if 1
int main(int argc, char *argv[])
{
        ios::sync_with_stdio(false);
        auto obj = new TrendAndCountermeasures_PineDecorationSequence1();
        obj->solve();
        delete obj;
        return 0;
}
#endif
0