Submission #950001

# Submission time Handle Problem Language Result Execution time Memory
950001 2024-03-20T03:06:58 Z Pragmatism Money (IZhO17_money) C++17
0 / 100
1 ms 604 KB
//Bismillahir-Rahmanir-Rahim

#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,sse4,sse4.1,sse4.2,popcnt,avx,avx2")

#define pb push_back
#define pii pair <int, int>
#define pll pair <long long, long long>
#define pld pair <long double, long double>
#define ll long long
#define ld long double
#define x first
#define y second
#define all(v) v.begin(),v.end()
#define sz(s) (int)s.size()
#define skip continue
#define bpop(x) (ll)__builtin_popcountll(x)

using namespace std;

const int N = 1e6 + 7;
const int M = 1e5 + 7;
const int maxA = 1e5 + 7;
const int inf = 1e9 + 7;
const ll INF = 2e18 + 7;
const int MOD = 998244353;
const ld eps = 1e-9;

pii dir[] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//clock_t start = clock();

//#define int long long

int n, a[N];
int get(int len) {
    vector <bool> used(n + 1);
    for (int i = 1;i <= len;i++)used[a[i]] = 1;
    int last = inf;
    vector <int> add;
    int res = 1;
    bool ok = 1;
    for (int i = len + 1;i <= n;i++) {
        if (last <= a[i] || last == inf) {
            for (int x = last + 1;x < a[i];x++)ok &= (!used[x]);
            if (ok)add.pb(a[i]), last = a[i];
        }
        else ok = 0;
        if (!ok) {
            //cout << "add:\n";
            for (auto x : add)used[x] = 1;// cout << x << ' ';
            //cout << '\n';
            add.clear(), ok = 1;
            last = inf, i--, res++;
        }
    }
    return res + !add.empty();
}
void solve() {
    cin >> n;
    for (int i = 1;i <= n;i++)cin >> a[i];
    int ans = n;
    for (int i = 1;i <= n;i++) {
        if (a[i] < a[i - 1])break;
        ans = min(ans, get(i));
    }
    cout << ans;
}
signed main() {
    //srand(time(NULL));
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("subsequence.in", "r", stdin);
    //freopen("subsequence.out", "w", stdout);
    int test = 1;
    //cin >> test;
    for (int t = 1;t <= test;t++) {
        //cout << "Case " << t << ": ";
        solve();
    }
    return 0;
}

Compilation message

money.cpp:4: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
    4 | #pragma comment(linker, "/stack:200000000")
      |
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Runtime error 1 ms 604 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Runtime error 1 ms 604 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Runtime error 1 ms 604 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Runtime error 1 ms 604 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -