Submission #758066

# Submission time Handle Problem Language Result Execution time Memory
758066 2023-06-14T06:17:39 Z vjudge1 Money (IZhO17_money) C++17
9 / 100
1500 ms 332 KB
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
 
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
 
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
 
 
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#define endl '\n'
#define int long long
#define mod 998244353
using namespace std;

int a[1000001];
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    
    int n, finn = 1e18; cin >> n;
    for(int i = 0; i < n; i++) cin >> a[i];
    
    for(int i = 0; i < (1 << n); i++){
        vector<vector<int>>d;
        vector<int>p;
        int ans = 0;
        for(int j = 0; j < n; j++){
            if(i & (1 << j)){
                p.push_back(a[j]);
                d.push_back(p);
                p.clear();
            }else{
                p.push_back(a[j]);
            }
        }
        if(p.size()) d.push_back(p);
        ans = d.size();
        deque<int>y;
        for(int j = 0; j < d.size(); j++){
            if(y.empty()){
                for(int k = 0; k < d[j].size(); k++) {
                    y.push_back(d[j][k]);
                }
            }else{
                deque<int>w;
                while(y.size()){
                    if(y.size() and y.front() <= d[j][0]){
                        w.push_back(y.front());
                        y.pop_front();
                    }else{
                        break;
                    }
                }
                for(int k = d[j].size() - 1; k >= 0; k--){
                    y.push_front(d[j][k]);
                }
                while(w.size()){
                    y.push_front(w.back());
                    w.pop_back();
                }
            }
            
        }
        int bad = 0;
        for(int j = 1; j < y.size(); j++){
            if(y[j] < y[j - 1]) bad = 1;
        }
        
        if(!bad) {
            finn = min(finn, ans);
        }
    }
    cout << finn;
    
    return 0;
}

Compilation message

money.cpp: In function 'int main()':
money.cpp:115:26: 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]
  115 |         for(int j = 0; j < d.size(); j++){
      |                        ~~^~~~~~~~~~
money.cpp:117:34: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  117 |                 for(int k = 0; k < d[j].size(); k++) {
      |                                ~~^~~~~~~~~~~~~
money.cpp:141:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::deque<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  141 |         for(int j = 1; j < y.size(); j++){
      |                        ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 51 ms 212 KB Output is correct
18 Correct 21 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Execution timed out 1570 ms 332 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 51 ms 212 KB Output is correct
18 Correct 21 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Execution timed out 1570 ms 332 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 51 ms 212 KB Output is correct
18 Correct 21 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Execution timed out 1570 ms 332 KB Time limit exceeded
21 Halted 0 ms 0 KB -