Last active
January 27, 2019 10:39
-
-
Save fpdjsns/403eaec4e97d1fae08afc99142952b07 to your computer and use it in GitHub Desktop.
[Qualification Round 2017] Problem C. Bathroom Stalls : https://code.google.com/codejam/contest/3264486/dashboard#s=p2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Created by fpdjsns | |
// Copyright © 2019 fpdjsns. All rights reserved. | |
// | |
#include<iostream> | |
#include<map> | |
#include<algorithm> | |
using namespace std; | |
/* | |
* 시간복잡도 : O(logN) | |
* 공간복잡도 : O(logN) | |
*/ | |
int main() { | |
int T; | |
cin >> T; | |
for (int t = 1; t <= T; t++) { | |
long long int N, K; | |
cin >> N >> K; | |
pair<long long int, long long int> answer(-1, -1); | |
map<long long int, long long int> m; // key: 연속된 자리 수, value: key의 개수 | |
m[N] = 1; | |
map<long long int, long long int>::iterator it; | |
long long int n = N; | |
while (K > 0) | |
{ | |
it = --m.end(); | |
n = it->first; | |
long long int cnt = it->second; | |
m.erase(it); | |
K -= cnt; | |
m[n / 2] += cnt;// big | |
m[(n - 1) / 2] += cnt;// small | |
} | |
answer = { n / 2, (n - 1) / 2 }; | |
printf("Case #%d: %lld %lld\n", t, answer.first, answer.second); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment