結果

問題 No.3054 Modulo Inequalities
ユーザー Rubikun
提出日時 2025-03-07 23:17:54
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,966 bytes
コンパイル時間 2,389 ms
コンパイル使用メモリ 204,588 KB
実行使用メモリ 23,484 KB
最終ジャッジ日時 2025-03-07 23:18:37
合計ジャッジ時間 42,141 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 5 WA * 1 TLE * 11 -- * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vvii vector<vector<pair<int,int>>>
#define vvll vector<vector<pair<ll,ll>>>
#define vst vector<string>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define mkunique(x) sort(all(x));(x).erase(unique(all(x)),(x).end())
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=15<<26;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    
    const int M=1000001;
    int N;cin>>N;
    vii S(N);
    int mib=M,mab=0;
    for(int i=0;i<N;i++){
        cin>>S[i].fi>>S[i].se;
        if(S[i].fi<S[i].se){
            chmax(mab,S[i].se+1);
            chmin(mib,S[i].se+1);
        }
    }
    shuffle(all(S),rng);
    
    vii A(M+1);
    for(int q=0;q<min(400,N);q++){
        for(int i=1;i<=M;i++){
            if(S[q].fi%i<S[q].se%i) A[i].fi++;
        }
    }
    A[1].fi=INF;
    A[mib].fi=INF;
    A[mab].fi=INF;
    
    for(int i=1;i<=M;i++) A[i].se=i;
    sort(all(A));
    reverse(all(A));
    
    int ma=-1,ans=INF;
    for(int q=0;q<400;q++){
        int cn=0;
        for(int i=0;i<N;i++){
            if(S[i].fi%A[q].se<S[i].se%A[q].se) cn++;
        }
        if(chmax(ma,cn)) ans=A[q].se;
        else if(ma==cn) chmin(ans,A[q].se);
        
        //cout<<A[q].se<<" "<<cn<<endl;
    }
    cout<<ans<<endl;
    
    
}


0