QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#317590#7560. Computer Networkbobbilyking#WA 0ms3572kbC++202.5kb2024-01-29 06:53:472024-01-29 06:53:47

Judging History

你现在查看的是最新测评结果

  • [2024-01-29 06:53:47]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3572kb
  • [2024-01-29 06:53:47]
  • 提交

answer

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template<typename T>
ostream_iterator<T> oit(){
    return ostream_iterator<T>(cout," ");
}
template<typename T>
ostream_iterator<T> oit(const string &s){
    return ostream_iterator<T>(cout,s.c_str());
}

struct chash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
 
template<typename T, typename U> using pb_map = gp_hash_table<T, U, chash>;
template<typename T> using pb_set = gp_hash_table<T, null_type, chash>;
#define K first
#define V second
#define K first
#define V second
#define G(x) ll x; cin >> x;
#define GD(x) ld x; cin >> x;
#define GS(s) string s; cin >> s;
#define EX(x) { cout << x << '\n'; exit(0); }
#define A(a) (a).begin(), (a).end()
#define F(i, l, r) for (ll i = l; i < (r); ++i)

typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;

constexpr ll NN = 2e5;
constexpr ll M = 1000000007;

int n;
vll a; 
int best_so_far;

void greedy(){
    vll stk;
    ll v = 0;
    ll nn = n;
    auto itr = a.begin(); 
    while (nn--) {
        ll x = *itr; itr = std::next(itr);
        while (stk.size() and stk.back() > x) stk.pop_back(), ++v;
        if (stk.size() and stk.back() == x); 
        else stk.push_back(x);
    } 
    best_so_far = v + stk.size();
}
int c = 0;
void rec(int i, int score){
    c++;
    if(score >= best_so_far) {
        return;
    }
    if(i==n){
        best_so_far=min(best_so_far,n);
        return;
    } 
    score += !!a[i];
    ll sub = a[i];
    for(int j = i;j<n;j++){
        a[j] -= sub;
        rec(i+1,score);
    }
    //undo
    for(int j = i;j<n;j++) a[j]-=sub;
}


void run()
{
    cin >> n; a.resize(n); for(ll &x : a) cin >> x;
    greedy();

    if(best_so_far >= n/2 + 1){
        cout << best_so_far << '\n'; return;
    }
    rec(0,0);
    cout << best_so_far << '\n'; 
}

int main()
{
    //KING OF THE WORLD...... U.W.T.B
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t; t=1; while(t--) run();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3572kb

input:

5
1 2 3 4 5
6 6 6 6 7

output:

5

result:

wrong answer 1st numbers differ - expected: '9', found: '5'