Submission #5826038


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) x.begin(),x.end()
#define dmp(x) cerr<<#x<<":"<<x<<endl
typedef pair<int,int> P;
typedef pair<int,P> PP; 
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
const int MOD = 1e9+7;

signed main(){
  int n,q;
  cin>>n>>q;
  for(int i=0;i<q;i++){
    int v,w;
    cin>>v>>w;
    if(n==0){
	 cout<<min(n,w)<<endl;
	 return 0;
    }
    vector<int> vv,wv;
    while(v>1){
	 vv.pb(v);
	 v=(v+1)/n;
    }
    while(w>1){
	 wv.pb(w);
	 w=(w+1)/n;
    }
    sort(all(vv));
    sort(all(wv));
    int ans=1;
    for(int j=0;j<sz(vv)&&j<sz(wv);j++){
	 if(vv[j]!=wv[j])break;
	 ans=vv[j];
    }
    cout<<ans<<endl;
  }
  return 0;
}

Submission Info

Submission Time
Task B - Evergrowing Tree
User shake
Language C++14 (GCC 5.4.1)
Score 0
Code Size 942 Byte
Status WA
Exec Time 2106 ms
Memory 1050960 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 100
Status
AC × 2
AC × 4
WA × 13
TLE × 3
Set Name Test Cases
Sample a01, a02
All a01, a02, b03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20
Case Name Status Exec Time Memory
a01 AC 1 ms 256 KB
a02 AC 1 ms 256 KB
b03 TLE 2106 ms 1049680 KB
b04 AC 258 ms 384 KB
b05 TLE 2106 ms 1050960 KB
b06 WA 440 ms 384 KB
b07 WA 442 ms 384 KB
b08 TLE 2106 ms 1050064 KB
b09 WA 443 ms 512 KB
b10 AC 400 ms 384 KB
b11 WA 412 ms 384 KB
b12 WA 394 ms 384 KB
b13 WA 359 ms 384 KB
b14 WA 284 ms 384 KB
b15 WA 284 ms 384 KB
b16 WA 266 ms 384 KB
b17 WA 266 ms 384 KB
b18 WA 267 ms 384 KB
b19 WA 265 ms 384 KB
b20 WA 253 ms 384 KB