Submission

Status:

(PPPPPPPPPPPPPPP)(PPPPPPPP)(PPPPPPPPPP)(-SSSSSSSSS)(-SSSSSSSSS)(-SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS)

Subtask/Task Score:

{3/3}{7/7}{12/12}{0/17}{0/21}{0/40}

Score: 22

User: saganegadih

Problemset: รถไฟตู้เสบียง (Dining Car)

Language: cpp

Time: 0.002 second

Submitted On: 2026-06-01 18:15:39

#include <bits/stdc++.h>
#include "dining_car.h"

using namespace std;

// you can also write additional functions here


pair < int, int > locate_dining_cars(int N)
{
	//write your code here

	//you can call "compare_cars(i,j)"
	int k;
	int init = compare_cars(1,N);
	int eq[2] = {1,N};
    int scope[] = {1,N-1};


    if(N<=50){
    	if(init == -1) {
    		k = N;
    		while(compare_cars(1,k)!=0) {
    			k--;
    		}
    
    		eq[0] = 1;
    		eq[1] = k;
    	}
    	if(init == 1) {
    		k = 1;
    		while(compare_cars(k,N)!=0) {
    			k++;
    		}
    
    		eq[0] = k;
    		eq[1] = N;
    	}
    	while(compare_cars(eq[0]+1,eq[1])==-1) {
    		eq[0]++;
    		eq[1]--;
    	}
    	
    }else{
    	eq[0] = 1;
        eq[1] = 2;
        int sq;
        while(scope[0] != scope[1]){
            sq = compare_cars((int)floor((scope[0]+scope[1])/2),(int)floor((scope[0]+scope[1])/2)+1);
            if(sq==1){
                scope[0] = (int)floor((scope[0]+scope[1])/2)+1;
            }
            if(sq==-1){
                scope[1] = (int)floor((scope[0]+scope[1])/2)-1;
            }
            if(sq==0){
                scope[0] = (int)floor((scope[0]+scope[1])/2);
                scope[1] = (int)floor((scope[0]+scope[1])/2);
            }
        }
        eq[0] = scope[0];
        eq[1] = scope[0]+1;
    }
    int max,min;
    if(eq[0]>eq[1]) {
    	max = eq[0];
    	min = eq[1];
    } else {
    	max = eq[1];
    	min = eq[0];
    }
	return make_pair(min, max);
}