답안 #368524

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
368524 2021-02-20T05:01:22 Z cpp219 중앙값 배열 (balkan11_medians) C++14
15 / 100
128 ms 12908 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 2e5 + 9;
const ll inf = 1e16 + 7;
typedef pair<int,int> LL;
vector<ll> ans;
set<ll> s;
ll n,b[N],was[N];

void Out(){
    for (auto i : s) cout<<i<<" ";
}

int main(){
    //ios_base::sync_with_stdio(0);
    //cin.tie(0); cout.tie(0);
    #define task "test"
    if (fopen(task".INP","r")){
        freopen(task".INP","r",stdin);
        //freopen(task".OUT","w",stdout);
    }
    cin>>n;
    for (ll i = 1;i <= 2*n - 1;i++) s.insert(i);
    for (ll i = 1;i <= n;i++) cin>>b[i],s.erase(b[i]);
    ans.push_back(b[1]); was[b[1]] = 1;
    for (ll i = 2;i <= n;i++){
        if (!was[b[i]]) ans.push_back(b[i]); //Out(); cout<<" x ";
        if (was[b[i]]){
            ans.push_back(*s.begin()),s.erase(s.begin());
            ans.push_back(*prev(s.end())),s.erase(prev(s.end()));
        }
        else if (b[i - 1] > b[i]) ans.push_back(*s.begin()),s.erase(s.begin());
        else if (b[i - 1] < b[i]) ans.push_back(*prev(s.end())),s.erase(prev(s.end()));
        was[b[i]] = 1; //Out(); cout<<"\n";
    }
    //exit(0);
    //for (auto i : s) cout<<i<<" "; exit(0);
    for (auto i : ans) cout<<i<<" ";
}

Compilation message

medians.cpp: In function 'int main()':
medians.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   23 |         freopen(task".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Correct 1 ms 364 KB Output is correct
4 Incorrect 1 ms 364 KB Output isn't correct
5 Incorrect 1 ms 364 KB Output isn't correct
6 Correct 1 ms 364 KB Output is correct
7 Incorrect 1 ms 364 KB Output isn't correct
8 Incorrect 1 ms 512 KB Output isn't correct
9 Incorrect 1 ms 364 KB Output isn't correct
10 Incorrect 1 ms 364 KB Output isn't correct
11 Incorrect 1 ms 364 KB Output isn't correct
12 Incorrect 1 ms 364 KB Output isn't correct
13 Incorrect 1 ms 492 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 620 KB Output isn't correct
2 Incorrect 5 ms 748 KB Output isn't correct
3 Incorrect 12 ms 1516 KB Output isn't correct
4 Incorrect 20 ms 2284 KB Output isn't correct
5 Incorrect 43 ms 4332 KB Output isn't correct
6 Incorrect 81 ms 8540 KB Output isn't correct
7 Incorrect 128 ms 12908 KB Output isn't correct