Submission #5826046


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==1){
	 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 944 Byte
Status WA
Exec Time 447 ms
Memory 512 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 100
Status
AC × 2
AC × 5
WA × 15
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 AC 1 ms 256 KB
b04 AC 263 ms 384 KB
b05 WA 1 ms 256 KB
b06 WA 447 ms 384 KB
b07 WA 441 ms 384 KB
b08 WA 1 ms 256 KB
b09 WA 439 ms 512 KB
b10 AC 418 ms 384 KB
b11 WA 398 ms 384 KB
b12 WA 375 ms 384 KB
b13 WA 359 ms 384 KB
b14 WA 286 ms 384 KB
b15 WA 283 ms 384 KB
b16 WA 270 ms 384 KB
b17 WA 270 ms 384 KB
b18 WA 268 ms 384 KB
b19 WA 266 ms 384 KB
b20 WA 258 ms 384 KB