Submission #5825982


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;
    vector<int> vv,wv;
    while(v){
	 vv.pb(v);
	 v=(v+1)/n;
    }
    while(w){
	 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 878 Byte
Status WA
Exec Time 2106 ms
Memory 1050832 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 100
Status
AC × 2
AC × 4
WA × 10
TLE × 6
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 2105 ms 1049424 KB
b04 AC 285 ms 384 KB
b05 TLE 2106 ms 1050192 KB
b06 TLE 2105 ms 1050832 KB
b07 TLE 2105 ms 1050064 KB
b08 TLE 2105 ms 1049808 KB
b09 TLE 2105 ms 1049040 KB
b10 AC 442 ms 384 KB
b11 WA 406 ms 384 KB
b12 WA 381 ms 384 KB
b13 WA 364 ms 512 KB
b14 WA 294 ms 384 KB
b15 WA 288 ms 384 KB
b16 WA 269 ms 384 KB
b17 WA 281 ms 384 KB
b18 WA 271 ms 384 KB
b19 WA 276 ms 384 KB
b20 WA 258 ms 384 KB