답안 #758246

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
758246 2023-06-14T10:15:51 Z vjudge1 Money (IZhO17_money) C++17
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int mxN = 1e6 + 7;

int n, arr[mxN];

int rec(int i, vector<vector<int>> vec) {
    if (i == n) {
        bool ok = true;
        set<int> cur;
        for (int i = 0; i < vec.size() && ok; ++i) {
            assert(vec[i].size());
            auto it1 = cur.upper_bound(vec[i][0]);
            auto it2 = cur.upper_bound(vec[i].back());

            if (it1 != it2) {
                ok = false;
            }

            for (auto x : vec[i]) {
                cur.insert(x);
            }
        }
        
        return (ok ? vec.size() : n);
    }
    
    int res = n;
    if (vec.size() && vec.back().back() <= arr[i]) {
        vec.back().push_back(arr[i]);
        res = min(res, rec(i + 1, vec));
        vec.back().pop_back();
    }
    vec.push_back({arr[i]});
    return min(res, rec(i + 1, vec));
}

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    cin >> n;
    
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
    }

    cout << rec(0, {});
}

Compilation message

money.cpp: In function 'long long int rec(long long int, std::vector<std::vector<long long int> >)':
money.cpp:14:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |         for (int i = 0; i < vec.size() && ok; ++i) {
      |                         ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -