# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
747488 |
2023-05-24T08:21:20 Z |
vjudge1 |
Kralj (COCI16_kralj) |
C++17 |
|
563 ms |
100268 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[2000001],p[2000001],v[2000001];
int freq[2000001],pre[2000001],suf[2000001];
vector<int>store[2000001];
int vs[2000001],mn[2000001];
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, ans = 0; cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= n; i++) cin >> p[i];
for(int i = 1; i <= n; i++) {
cin >> v[i];
store[a[i]].push_back(v[i]);
}
for(int i = 1; i <= n; i++) freq[a[i]]++;
for(int i = 1; i <= n; i++) pre[i] += pre[i - 1] + freq[i];
for(int i = n; i >= 1; i--) suf[i] += suf[i + 1] + freq[i];
for(int i = n; i >= 1; i--){
int f = suf[i];
suf[i] = n - i + 1 - f;
}
mn[n + 1] = 1e18;
for(int i = n; i >= 1; i--){
mn[i] = min(mn[i + 1], suf[i]);
}
int starting_point = 0;
for(int i = 1; i < n; i++){
if(pre[i] <= i and pre[i] - i <= mn[i + 1]){
starting_point = i;
}
}
multiset<int>idk;
for(int i = starting_point; i <= n; i++){
int j = 0;
while(j < store[i].size()){
idk.insert(store[i][j]);
j++;
}
if(idk.empty()) continue;
auto f = idk.lower_bound(p[i]);
if(f != idk.end()){
ans++;
idk.erase(f);
}else{
idk.erase(*idk.begin());
}
}
for(int i = 1; i <= starting_point; i++){
if(i == starting_point){
if(vs[i]) continue;
}else{
int j = 0;
while(j < store[i].size()){
idk.insert(store[i][j]);
j++;
}
}
if(idk.empty()) continue;
auto f = idk.lower_bound(p[i]);
if(f != idk.end()){
ans++;
idk.erase(f);
}else{
idk.erase(*idk.begin());
}
}
cout << ans;
return 0;
}
/*
5 6 30 4
1 0 5
0 2 2
2 3 4
3 4 1
2 4 3
0 3 1
1 1 1 1 1
*/
Compilation message
kralj.cpp: In function 'int main()':
kralj.cpp:135:17: 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]
135 | while(j < store[i].size()){
| ~~^~~~~~~~~~~~~~~~~
kralj.cpp:154:21: 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]
154 | while(j < store[i].size()){
| ~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
563 ms |
90304 KB |
Output is correct |
2 |
Correct |
370 ms |
89260 KB |
Output is correct |
3 |
Correct |
488 ms |
99196 KB |
Output is correct |
4 |
Correct |
510 ms |
100268 KB |
Output is correct |
5 |
Incorrect |
334 ms |
80388 KB |
Output isn't correct |
6 |
Incorrect |
316 ms |
80840 KB |
Output isn't correct |
7 |
Incorrect |
344 ms |
83532 KB |
Output isn't correct |
8 |
Incorrect |
311 ms |
80560 KB |
Output isn't correct |
9 |
Incorrect |
375 ms |
85404 KB |
Output isn't correct |
10 |
Incorrect |
345 ms |
83988 KB |
Output isn't correct |