This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "popa.h"
using namespace std;
// int gc(int a, int b){
// if(a==0 || b==0){
// return a+b;
// }
// return gc(b%a,a);
// }
// vector<int> inp;
// int query(int a, int b, int c, int d){
// int x = inp[a];
// int y = inp[c];
// for(int i = a; i<=b; i++){
// x = gc(x,inp[i]);
// }
// for(int i = c; i<=d; i++){
// y = gc(y,inp[i]);
// }
// return (x==y?1:0);
// }
int solve(int n, int* left, int *right){
for(int i = 0; i<n; i++){
left[i] = -1;
right[i] = -1;
}
vector<int> tops;
tops.push_back(0);
for(int i = 1; i<n; i++){
vector<int> li;
while(tops.size()>0){
if(query(tops.back(),i,i,i)==1){
li.push_back(tops.back());
tops.pop_back();
}
else{
break;
}
}
for(int j = 1; j<li.size(); j++){
right[li[j]] = li[j-1];
}
if(li.size()>0){
left[i] = li.back();
}
tops.push_back(i);
}
for(int i = 1; i<tops.size(); i++){
right[tops[i-1]] = tops[i];
}
return tops[0];
}
// int main(){
// inp.push_back(12);
// inp.push_back(4);
// inp.push_back(16);
// inp.push_back(2);
// inp.push_back(2);
// inp.push_back(20);
// int a[6];
// int b[6];
// cout << solve(6,a,b) << endl;
// for(int i = 0; i<6; i++){
// cout << a[i] << " ";
// }
// cout << endl;
// for(int i = 0; i<6; i++){
// cout << b[i] << " ";
// }
// cout << endl;
// }
Compilation message (stderr)
popa.cpp: In function 'int solve(int, int*, int*)':
popa.cpp:40:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 1; j<li.size(); j++){
~^~~~~~~~~~
popa.cpp:48:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 1; i<tops.size(); i++){
~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |