제출 #1345219

#제출 시각아이디문제언어결과실행 시간메모리
1345219makskusGrid Coloring (JOI25_ho_t1)C++20
100 / 100
213 ms28624 KiB
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <cmath>
#include <climits>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <functional>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <chrono>
#include <random>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define rep(a,b) for(int a = 0;a<b;a++)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(),a.end()
const int inf = 1e9;
const ll infl = 1e18;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;

    vector<int> a(n);
    vector<int> b(n);
    
    rep(i, n){
        cin >> a[i];
    }
    rep(i, n){
        cin >> b[i];
    }

    vector<int> pref_wier(n);
    vector<int> pref_kol(n);

    map<int, ll> zlicz;

    rep(i, n){
        if(i == 0){
            int sigmaaaa = 0;
        }
        else if(i == 1){
            pref_wier[i] = a[i];
        }
        else{
            pref_wier[i] = max(pref_wier[i-1], a[i]);
        }
        zlicz[a[i]]++; 
    }

    rep(i, n){
        if(i == 0){
            int sigmaaaa = 0;
        }
        else if(i == 1){
            pref_kol[i] = b[i];
            zlicz[b[i]]++;
        }
        else{
            pref_kol[i] = max(pref_kol[i-1], b[i]);
            zlicz[b[i]]++;
        }
    }

    for(int i = 1; i < n; i++){
        int d = upper_bound(pref_kol.begin() + 1, pref_kol.end(), pref_wier[i]) - (pref_kol.begin() + 1);
        zlicz[pref_wier[i]] += d;
        
        int d2 = lower_bound(pref_wier.begin() + 1, pref_wier.end(), pref_kol[i]) - (pref_wier.begin() + 1);
        zlicz[pref_kol[i]] += d2;
    }
    
    ll ile = -1;
    int co = -1;
    for(auto para : zlicz){
        if(ile <= para.nd){
            co = para.st;
            ile = para.nd;
        }
    }
    
    cout << co << " " << ile << "\n";

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...