78502024-01-11 13:21:30hackemonKártyajátékcpp17Wrong answer 18/3050ms14392 KiB
#include <bits/stdc++.h>
using namespace std;
//using namespace std::chrono;

#define pii pair<int,int>
#define pb push_back
#define vi vector<int>
#define vb vector<bool>
#define vl vector<ll>
#define vvi vector<vi>
#define vvb vector<vb>
#define vvl vector<vl>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define fScan {ios_base::sync_with_stdio(false); cin.tie(NULL);}
#define rep(i, a, b) for(int i = a; i < (b); i++)
#define REP(i, n) for(int i = 0;i <(n); i++)
using ll = long long;
using ld = long double;
ll mod = 1000000007;

const char ny =  '\n';

bool prime(ll a) {
    if (a==1) return 0;
    for (int i=2;i*i<=a;++i)
    {
        if (a%i==0) return 0;
    }
    return 1;
}

ll gcd(ll a,ll b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b)
{
    return a/gcd(a,b)*b;
}

ll min(int a, ll b) {
    if(a< b) return a;
    else return b;
}



void solve() { 
    int n, k;
    cin >> n >> k; 
    vector<long long> f(k);
    set<long long> elemek;

    for(int i = 0;i < k;i++ ) {
        cin >> f[i];
        elemek.insert(f[i]);
    }

    int ans = 0;

    for(int i = 0;i < k;i++ ) {
        auto pos = elemek.find(f[i]);
        if(pos == elemek.end()) {
            continue;
        } else { 
            if(elemek.begin() == pos) { 
                elemek.erase(elemek.begin());
            } else { 
                int counter = 0;
                while(elemek.begin() != pos) {
                    elemek.erase(elemek.begin());
                    counter++;
                }
                if(counter > 0) ans++;
                elemek.erase(elemek.begin());
            }
        }
    }
    cout << ans << endl;
    }


int main()
{
    fScan

    int t = 1;
    //comment out if necessary
    //cin>> t;


    //auto start = high_resolution_clock::now();
    while(t-- ) {
        solve();
    }
    //auto end = high_resolution_clock::now();
    //auto dur = duration_cast<milliseconds>(end-start);
    //cout<< "runtime: " << dur.count() << " milliseconds" << '\n';
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base18/30
1Accepted0/03ms1828 KiB
2Wrong answer0/03ms2064 KiB
3Accepted1/13ms2272 KiB
4Accepted1/13ms2456 KiB
5Accepted1/13ms2572 KiB
6Accepted2/23ms2940 KiB
7Accepted2/23ms2896 KiB
8Accepted2/23ms3200 KiB
9Accepted1/135ms10536 KiB
10Accepted2/250ms14212 KiB
11Accepted3/346ms14288 KiB
12Accepted3/348ms14392 KiB
13Wrong answer0/13ms3676 KiB
14Wrong answer0/23ms3708 KiB
15Wrong answer0/33ms3920 KiB
16Wrong answer0/33ms3900 KiB
17Wrong answer0/33ms4000 KiB