Submission #31672436


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)

std::vector<std::string> split(const std::string& text, const char delim);

using ll = long long int;
using llu = unsigned long long int;

int main(){
    string buffer;
    getline(cin, buffer);
    auto input_list = split(buffer, ' ');
    const int N = stoi(input_list[0]);
    const int W = stoi(input_list[1]);

    getline(cin, buffer);
    vector<int> a_list;
    a_list.reserve(N+1);
    for(const auto& str_item : split(buffer, ' ')){
        a_list.emplace_back(stoi(str_item));
    }

    map<int, int> number_map;

    // N=1の処理
    for(const auto& a : a_list){
        number_map[a]++;
    }

    if(N <= 1){
        int count = 0;
        for(const auto& pair : number_map){
            if(W < pair.first){
                break;
            }
            ++count;
        }
        cout << count << endl;
        return 0;
    }

    // N=2の処理
    for(int i = 0; i < N-1; ++i){
        for(int j = i + 1; j < N; ++j){
            const int sum = a_list[i] + a_list[j];
            number_map[sum]++;
        }
    }

    if(N <= 2){
        int count = 0;
        for(const auto& pair : number_map){
            if(W < pair.first){
                break;
            }
            ++count;
        }
        cout << count << endl;
        return 0;
    }

    // N=3の処理
    for(int i = 0; i < N - 2; ++i){
        for(int j = i + 1; j < N - 1; ++j){
            for(int k = j + 1; k < N; ++k){
                const int sum = a_list[i] + a_list[j] + a_list[k];
                number_map[sum]++;
            }
        }
    }

    int count = 0;
    for(const auto& pair : number_map){
        if(W < pair.first){
            break;
        }
        ++count;
    }
    cout << count << endl;

    return 0;
}

std::vector<std::string> split(const std::string& text, const char delim){
    std::vector<std::string> item_list;
    std::stringstream ss(text);
    std::string buffer;

    const size_t NUM_ITEM = std::count(text.begin(), text.end(), delim);
    item_list.reserve(NUM_ITEM + 1);

    while ( std::getline(ss, buffer, delim) ) {
        if (!buffer.empty()) {
                item_list.emplace_back(buffer);
        }
    }

    return item_list;
}

Submission Info

Submission Time
Task B - At Most 3 (Judge ver.)
User low10603
Language C++ (GCC 9.2.1)
Score 0
Code Size 2389 Byte
Status TLE
Exec Time 2208 ms
Memory 82320 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 200
Status
AC × 4
AC × 9
TLE × 3
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_small_00.txt, 01_small_01.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 03_corner_00.txt, 03_corner_01.txt, 03_corner_02.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 2 ms 3532 KiB
00_sample_01.txt AC 2 ms 3436 KiB
00_sample_02.txt AC 3 ms 3452 KiB
00_sample_03.txt AC 3 ms 3460 KiB
01_small_00.txt AC 2 ms 3516 KiB
01_small_01.txt AC 2 ms 3464 KiB
02_random_00.txt TLE 2208 ms 74828 KiB
02_random_01.txt TLE 2208 ms 75180 KiB
02_random_02.txt TLE 2208 ms 82320 KiB
03_corner_00.txt AC 29 ms 3424 KiB
03_corner_01.txt AC 22 ms 3436 KiB
03_corner_02.txt AC 625 ms 51228 KiB