結果

問題 No.689 E869120 and Constructing Array 3
ユーザー とばりとばり
提出日時 2018-08-14 19:06:45
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 178 ms / 1,000 ms
コード長 3,296 bytes
コンパイル時間 2,443 ms
コンパイル使用メモリ 170,272 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 17:11:35
合計ジャッジ時間 6,876 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 177 ms
4,348 KB
testcase_01 AC 174 ms
4,348 KB
testcase_02 AC 175 ms
4,348 KB
testcase_03 AC 174 ms
4,348 KB
testcase_04 AC 174 ms
4,348 KB
testcase_05 AC 174 ms
4,348 KB
testcase_06 AC 176 ms
4,348 KB
testcase_07 AC 175 ms
4,348 KB
testcase_08 AC 174 ms
4,348 KB
testcase_09 AC 175 ms
4,348 KB
testcase_10 AC 177 ms
4,348 KB
testcase_11 AC 174 ms
4,348 KB
testcase_12 AC 178 ms
4,348 KB
testcase_13 AC 176 ms
4,348 KB
testcase_14 AC 175 ms
4,348 KB
testcase_15 AC 177 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:122:16: warning: 'count6' may be used uninitialized [-Wmaybe-uninitialized]
  122 |     repeat (i, count6) c.push_back(6);
      |                ^~~~~~
main.cpp:85:33: note: 'count6' was declared here
   85 |     int count3, count4, count5, count6;
      |                                 ^~~~~~
main.cpp:121:16: warning: 'count5' may be used uninitialized [-Wmaybe-uninitialized]
  121 |     repeat (i, count5) c.push_back(5);
      |                ^~~~~~
main.cpp:85:25: note: 'count5' was declared here
   85 |     int count3, count4, count5, count6;
      |                         ^~~~~~
main.cpp:120:16: warning: 'count4' may be used uninitialized [-Wmaybe-uninitialized]
  120 |     repeat (i, count4) c.push_back(4);
      |                ^~~~~~
main.cpp:85:17: note: 'count4' was declared here
   85 |     int count3, count4, count5, count6;
      |                 ^~~~~~
main.cpp:119:16: warning: 'count3' may be used uninitialized [-Wmaybe-uninitialized]
  119 |     repeat (i, count3) c.push_back(3);
      |                ^~~~~~
main.cpp:85:9: note: 'count3' was declared here
   85 |     int count3, count4, count5, count6;
      |         ^~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using int64 = long long;
using uint64 = unsigned long long;

#define repeat(i, x) for (int64 i = 0; (i) < (x); (i)++)
#define rev_repeat(i, x) for (int64 i = (x) - 1; (i) >= 0; (i)--)
#define countup(i, n) for (int64 i = 0; (i) <= (n); (i)++)
#define countdown(i, n) for (int64 i = (n); (i) >= 0; (i)--)
#define range(i, a, b) for (int64 i = (a); (i) < (b); (i)++)
#define traverse(it, ctn) for (auto it = begin(ctn); (it) != end(ctn); (it)++)
#define rev_traverse(it, ctn) for (auto it = rbegin(ctn); (it) != rend(ctn); (it)++)

template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec)
{
    os << "[";
    repeat (i, vec.size())
    {
        os << (i == 0 ? "" : ", ") << vec[i];
    }
    os << "]";
    return os;
}

template<typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& p)
{
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template<typename T>
ostream& operator<<(ostream& os, set<T>& s)
{
    os << "{";
    traverse (it, s)
    {
        if (it != s.begin()) os << ", ";
        os << *it;
    }
    os << "}";
    return os;
}

template<typename K, typename V>
ostream& operator<<(ostream& os, map<K, V>& m) 
{
    os << "{";
    traverse (it, m)
    {
        if (it != m.begin()) os << ", ";
        os << it->first << ": " << it->second;
    }
    os << "}";
    return os;
}

//
// _______  _____  _______  _____  _______ _______ _____ _______ _____ _    _ _______ 
// |       |     | |  |  | |_____] |______    |      |      |      |    \  /  |______ 
// |_____  |_____| |  |  | |       |______    |    __|__    |    __|__   \/   |______ 
//
//  _____   ______  _____   ______  ______ _______ _______ _______ _____ __   _  ______   /
// |_____] |_____/ |     | |  ____ |_____/ |_____| |  |  | |  |  |   |   | \  | |  ____  / 
// |       |    \_ |_____| |_____| |    \_ |     | |  |  | |  |  | __|__ |  \_| |_____| .  
//

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int K;
    cin >> K;

    if (K == 0)
    {
        cout << 1 << endl;
        cout << 1 << endl;
        return 0;
    }
    // |  3   |  4   |   5   |   6   |
    int count3, count4, count5, count6;

    auto update = [&](int64 c3, int64 c4, int64 c5, int64 c6) {
        count3 = c3; count4 = c4; count5 = c5; count6 = c6;
    };

    countup (cnt3, 250)
    {
        countup (cnt4, 250)
        {
            if (cnt3 + cnt4 <= 250 and cnt3 * cnt4 == K)
            {
                update(cnt3, cnt4, 0, 0);
                continue;
            }

            countup (cnt5, 250)
            {

                if (cnt5 == 0 or (K - (cnt3 * cnt4)) % cnt5 != 0) continue;

                int cnt6 = (K - (cnt3 * cnt4)) / cnt5;

                assert(K == cnt3 * cnt4 + cnt5 * cnt6);

                if (cnt6 >= 0 and cnt3 + cnt4 + cnt5 + cnt6 <= 250)
                {
                    update(cnt3, cnt4, cnt5, cnt6);
                }
            }
        }
    }

    vector<int> c;
    repeat (i, count3) c.push_back(3);
    repeat (i, count4) c.push_back(4);
    repeat (i, count5) c.push_back(5);
    repeat (i, count6) c.push_back(6);

    cout << c.size() << endl;
    for (auto e : c)
    {
        cout << e << " ";
    }
    cout << endl;

    return 0;
}
0