Submission #342886

#TimeUsernameProblemLanguageResultExecution timeMemory
342886maskoffMoney (IZhO17_money)C++17
9 / 100
1 ms384 KiB
#include <bits/stdc++.h> #define file "" #define all(x) x.begin(), x.end() #define sc second #define fr first #define pb push_back #define mp make_pair using namespace std; typedef long long ll; typedef pair<int, int> pii; const ll inf = 1e18 + 5; const ll mod = 1e9 + 7; const int N = 1e5 + 5; int dx[] = {+1, 0, -1, 0}; int dy[] = {0, +1, 0, -1}; int n; int a[N]; void solve1() { int res = 40; for (int mask = 1; mask < (1 << n); mask += 2) { //cerr << mask << endl; vector<int> v[20]; int cur = 0; for (int i = 0; i < n; i++) { if (mask & (1 << i)) v[++cur].pb(a[i + 1]); else v[cur].pb(a[i + 1]); } vector<int> ans; for (int to : v[1]) ans.pb(to); if (!is_sorted(all(ans))) continue; for (int i = 2; i <= cur; i++) { //cerr << "i : " << i << endl; for (int p = 0; p <= ans.size(); p++) { vector<int> d = ans; //cerr << "p : " << p << endl; for (int j = 0; j < v[i].size(); j++) d.insert(d.begin() + p + j, v[i][j]); //for (int to : d) cerr << to << " "; //cerr << endl; if (is_sorted(all(d))) { ans = d; goto pos; } } goto here; pos:; } res = min(res, cur); here:; } cout << res; } int main() { ios_base :: sync_with_stdio(false); cin.tie(nullptr); srand(time(nullptr)); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; if (n <= 8) solve1(); return 0; }

Compilation message (stderr)

money.cpp: In function 'void solve1()':
money.cpp:44:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |      for (int p = 0; p <= ans.size(); p++) {
      |                      ~~^~~~~~~~~~~~~
money.cpp:47:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |        for (int j = 0; j < v[i].size(); j++)
      |                        ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...