Submission #1398002


Source Code Expand

#include <stdio.h>
#include <vector>
using namespace std;

int main()
{
	int Test; scanf ("%d",&Test); while (Test--){
		long long N,K;
		scanf ("%lld %lld",&N,&K);

		if (K > (N + 1) / 2) puts("-1");
		else{
			long long u = (N + 1) / 2 * 2 - 1;
			vector<pair<long long, long long> > intv;
			while (u >= 1){
				long long l;
				if (u % 3 == 0) l = u / 3 + 1;
				else if (u % 3 == 1) l = (u - 1) / 3;
				else l = u / 3 + 1;
				if (l % 2 == 0) l++;
				intv.push_back({l,u});
				u = l - 2;
			}

			long long l = 1, r = N, a = N;
			while (l <= r){
				long long m = (l + r * 2) / 3;
				long long c = 0;
				for (int i=0;i<intv.size();i++){
					long long step = (2ll << i);
					long long p = intv[i].first << i;
					long long q = intv[i].second << i;
					if (m < p) continue;
					if (m < q) c += (m - p) / step + 1;
					else c += (q - p) / step + 1;
				}

				if (c >= K){
					r = m - 1;
					a = m;
				}
				else l = m + 1;
			}
			printf ("%lld\n",a);
		}
	}

	return 0;
}

Submission Info

Submission Time
Task H - N and K
User august14
Language C++14 (GCC 5.4.1)
Score 750
Code Size 1038 Byte
Status AC
Exec Time 2845 ms
Memory 2176 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:7:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  int Test; scanf ("%d",&Test); while (Test--){
                              ^
./Main.cpp:9:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%lld %lld",&N,&K);
                            ^

Judge Result

Set Name subtask All
Score / Max Score 50 / 50 700 / 700
Status
AC × 33
AC × 45
Set Name Test Cases
subtask 00_small_00.txt, 01_small_01.txt, 02_small_02.txt, 04_small_03.txt, 04_small_04.txt, 04_small_05.txt, 04_small_06.txt, 04_small_07.txt, 04_small_08.txt, 04_small_09.txt, 04_small_10.txt, 04_small_11.txt, 04_small_12.txt, 04_small_13.txt, 04_small_14.txt, 04_small_15.txt, 04_small_16.txt, 04_small_17.txt, 04_small_18.txt, 04_small_19.txt, 04_small_20.txt, 04_small_21.txt, 04_small_22.txt, 04_small_23.txt, 04_small_24.txt, 04_small_25.txt, 04_small_26.txt, 04_small_27.txt, 04_small_28.txt, 04_small_29.txt, 04_small_30.txt, 04_small_31.txt, 04_small_32.txt
All 00_small_00.txt, 01_small_01.txt, 02_small_02.txt, 04_small_03.txt, 04_small_04.txt, 04_small_05.txt, 04_small_06.txt, 04_small_07.txt, 04_small_08.txt, 04_small_09.txt, 04_small_10.txt, 04_small_11.txt, 04_small_12.txt, 04_small_13.txt, 04_small_14.txt, 04_small_15.txt, 04_small_16.txt, 04_small_17.txt, 04_small_18.txt, 04_small_19.txt, 04_small_20.txt, 04_small_21.txt, 04_small_22.txt, 04_small_23.txt, 04_small_24.txt, 04_small_25.txt, 04_small_26.txt, 04_small_27.txt, 04_small_28.txt, 04_small_29.txt, 04_small_30.txt, 04_small_31.txt, 04_small_32.txt, 05_medium_33.txt, 06_medium_34.txt, 07_large_35.txt, 07_large_36.txt, 07_large_37.txt, 07_large_38.txt, 07_large_39.txt, 08_large_40.txt, 08_large_41.txt, 08_large_42.txt, 08_large_43.txt, 08_large_44.txt
Case Name Status Exec Time Memory
00_small_00.txt AC 1 ms 256 KB
01_small_01.txt AC 1 ms 256 KB
02_small_02.txt AC 1 ms 256 KB
04_small_03.txt AC 1 ms 256 KB
04_small_04.txt AC 1 ms 256 KB
04_small_05.txt AC 1 ms 256 KB
04_small_06.txt AC 1 ms 256 KB
04_small_07.txt AC 1 ms 256 KB
04_small_08.txt AC 1 ms 256 KB
04_small_09.txt AC 1 ms 256 KB
04_small_10.txt AC 1 ms 256 KB
04_small_11.txt AC 1 ms 256 KB
04_small_12.txt AC 1 ms 256 KB
04_small_13.txt AC 1 ms 256 KB
04_small_14.txt AC 1 ms 256 KB
04_small_15.txt AC 1 ms 256 KB
04_small_16.txt AC 1 ms 256 KB
04_small_17.txt AC 1 ms 256 KB
04_small_18.txt AC 1 ms 256 KB
04_small_19.txt AC 1 ms 256 KB
04_small_20.txt AC 1 ms 256 KB
04_small_21.txt AC 1 ms 256 KB
04_small_22.txt AC 1 ms 256 KB
04_small_23.txt AC 1 ms 256 KB
04_small_24.txt AC 1 ms 256 KB
04_small_25.txt AC 1 ms 256 KB
04_small_26.txt AC 1 ms 256 KB
04_small_27.txt AC 1 ms 256 KB
04_small_28.txt AC 1 ms 256 KB
04_small_29.txt AC 1 ms 256 KB
04_small_30.txt AC 1 ms 256 KB
04_small_31.txt AC 1 ms 256 KB
04_small_32.txt AC 1 ms 256 KB
05_medium_33.txt AC 75 ms 512 KB
06_medium_34.txt AC 124 ms 640 KB
07_large_35.txt AC 1422 ms 1280 KB
07_large_36.txt AC 1428 ms 1280 KB
07_large_37.txt AC 1421 ms 1280 KB
07_large_38.txt AC 1420 ms 1280 KB
07_large_39.txt AC 1426 ms 1280 KB
08_large_40.txt AC 2845 ms 2176 KB
08_large_41.txt AC 2813 ms 2048 KB
08_large_42.txt AC 2805 ms 2048 KB
08_large_43.txt AC 2807 ms 2048 KB
08_large_44.txt AC 2807 ms 2048 KB