Submission #1398018


Source Code Expand

#include <stdio.h>

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;
			long long intv[100][2]; int sz = 0;
			while (u >= 1){
				long long l;
				if (u % 3 == 1) l = u / 3;
				else l = u / 3 + 1;
				if (l % 2 == 0) l++;
				intv[sz][0] = l;
				intv[sz][1] = u;
				sz++;
				u = l - 2;
			}

			long long l = 1, r = N, a = N;
			while (l <= r){
				long long m = (l + r) / 2;
				long long c = 0;
				for (int i=0;i<sz;i++){
					long long t = m >> i;
					long long &p = intv[i][0];
					long long &q = intv[i][1];
					if (t < p) continue;
					if (t < q) c += (t - p) / 2 + 1;
					else c += (q - p) / 2 + 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 930 Byte
Status AC
Exec Time 508 ms
Memory 2048 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:5: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:7: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 0 ms 128 KB
01_small_01.txt AC 0 ms 128 KB
02_small_02.txt AC 1 ms 128 KB
04_small_03.txt AC 1 ms 128 KB
04_small_04.txt AC 1 ms 128 KB
04_small_05.txt AC 1 ms 128 KB
04_small_06.txt AC 1 ms 128 KB
04_small_07.txt AC 1 ms 128 KB
04_small_08.txt AC 1 ms 128 KB
04_small_09.txt AC 1 ms 128 KB
04_small_10.txt AC 1 ms 128 KB
04_small_11.txt AC 1 ms 128 KB
04_small_12.txt AC 1 ms 128 KB
04_small_13.txt AC 1 ms 128 KB
04_small_14.txt AC 1 ms 128 KB
04_small_15.txt AC 1 ms 128 KB
04_small_16.txt AC 1 ms 128 KB
04_small_17.txt AC 1 ms 128 KB
04_small_18.txt AC 1 ms 128 KB
04_small_19.txt AC 1 ms 128 KB
04_small_20.txt AC 1 ms 128 KB
04_small_21.txt AC 1 ms 128 KB
04_small_22.txt AC 0 ms 128 KB
04_small_23.txt AC 0 ms 128 KB
04_small_24.txt AC 0 ms 128 KB
04_small_25.txt AC 0 ms 128 KB
04_small_26.txt AC 1 ms 128 KB
04_small_27.txt AC 1 ms 128 KB
04_small_28.txt AC 1 ms 128 KB
04_small_29.txt AC 1 ms 128 KB
04_small_30.txt AC 1 ms 128 KB
04_small_31.txt AC 1 ms 128 KB
04_small_32.txt AC 0 ms 128 KB
05_medium_33.txt AC 31 ms 512 KB
06_medium_34.txt AC 43 ms 512 KB
07_large_35.txt AC 272 ms 1280 KB
07_large_36.txt AC 272 ms 1280 KB
07_large_37.txt AC 271 ms 1280 KB
07_large_38.txt AC 271 ms 1280 KB
07_large_39.txt AC 272 ms 1280 KB
08_large_40.txt AC 507 ms 2048 KB
08_large_41.txt AC 508 ms 2048 KB
08_large_42.txt AC 507 ms 2048 KB
08_large_43.txt AC 507 ms 2048 KB
08_large_44.txt AC 507 ms 2048 KB