지금 글을 쓰려고 보니, 붙어도 갈 생각이 없어서 후기를 작성을 안 해뒀다... 풀이 코드만 첨부한다.
7번은 시간 부족해서 문제 쳐다보지도 못 했던 기억만 남는다.
최종적으로 1차 코딩테스트는 합격했지만, 2차 코딩테스트가 ICPC와 예선과 일정이 겹쳐서 참여하지 않았다. ICPC 예선이랑 채용 일자가 겹치는 공고가 많아서 좀.. 그렇다.
1번
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename a, typename b>
ostream& operator<<(ostream& os, const pair<a, b>& pai) {
os << pai.first << ' ' << pai.second;
return os;
}
template<typename a, typename b>
istream& operator>>(istream& is, pair<a, b>& pai) {
is >> pai.first >> pai.second;
return is;
}
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
#define all(x) (x).begin(), (x).end()
#define INF (INT_MAX / 2)
#define MAX_N 10'005
#define MOD 1'000'000'007
int n;
int calcDate(const string& s) {
int year = atoi(s.substr(0, 4).c_str());
int month = atoi(s.substr(5, 2).c_str());
int day = atoi(s.substr(8, 2).c_str());
return day + month * 28 + year * 28 * 12;
}
vector<int> solution(string today, vector<string> terms, vector<string> privacies) {
vector<int> answer;
n = privacies.size();
int todayInt = calcDate(today);
for (int i = 0; i < n; ++i) {
int idx = privacies[i].find(' ');
int date = calcDate(privacies[i].substr(0, idx));
string term = privacies[i].substr(idx + 1, privacies[i].size() - idx);
for (int j = 0; j < terms.size(); ++j) {
int id = terms[j].find(' ');
string t = terms[j].substr(0, id);
if (term.compare(t) == 0) {
date += atoi(terms[j].substr(id + 1, terms[j].size() - id).c_str()) * 28;
break;
}
}
if (todayInt >= date) answer.emplace_back(i + 1);
}
return answer;
}
#ifndef ONLINE_JUDGE
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
return 0;
}
#endif
2번
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename a, typename b>
ostream& operator<<(ostream& os, const pair<a, b>& pai) {
os << pai.first << ' ' << pai.second;
return os;
}
template<typename a, typename b>
istream& operator>>(istream& is, pair<a, b>& pai) {
is >> pai.first >> pai.second;
return is;
}
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
#define all(x) (x).begin(), (x).end()
#define INF (INT_MAX / 2)
#define MAX_N 10'005
#define MOD 1'000'000'007
void adjust(int& idx, vector<int>& vec) {
while(idx >= 0 && !vec[idx]) --idx;
}
void calc(int& idx, vector<int>& vec, int cap) {
while(idx >= 0 && cap > 0) {
if (!vec[idx]) --idx;
else {
vec[idx]--;
cap--;
}
}
}
long long solution(int cap, int n, vector<int> deliveries, vector<int> pickups) {
long long answer = 0;
int idx1 = n - 1;
int idx2 = n - 1;
while(idx1 >= 0 && idx2 >= 0) {
adjust(idx1, deliveries);
adjust(idx2, pickups);
answer += max(idx1, idx2) * 2 + 2;
calc(idx1, deliveries, cap);
calc(idx2, pickups, cap);
}
while(idx1 >= 0) {
adjust(idx1, deliveries);
answer += idx1 * 2 + 2;
calc(idx1, deliveries, cap);
}
while(idx2 >= 0) {
adjust(idx2, pickups);
answer += idx2 * 2 + 2;
calc(idx2, pickups, cap);
}
return answer;
}
#ifndef ONLINE_JUDGE
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
return 0;
}
#endif
3번
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename a, typename b>
ostream& operator<<(ostream& os, const pair<a, b>& pai) {
os << pai.first << ' ' << pai.second;
return os;
}
template<typename a, typename b>
istream& operator>>(istream& is, pair<a, b>& pai) {
is >> pai.first >> pai.second;
return is;
}
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
#define all(x) (x).begin(), (x).end()
#define INF (INT_MAX / 2)
#define MAX_N 10'005
#define MOD 1'000'000'007
int sale[4] = {9, 8, 7, 6};
pii ans;
void pick(const vector<vector<int>>& users, const vector<int>& emoticons, vector<pii>& prices, int toPick) {
if (emoticons.size() == toPick) {
pii temp = {0, 0};
for (int i = 0; i < users.size(); ++i) {
int totalPrice = 0;
for (int j = 0; j < prices.size(); ++j) {
if (users[i][0] <= prices[j].first) {
totalPrice += prices[j].second;
}
}
if (totalPrice >= users[i][1]) {
temp.first++;
} else {
temp.second += totalPrice;
}
}
ans = max(ans, temp);
return;
}
for (int i = 0; i < 4; ++i) {
prices[toPick].first = (i + 1) * 10;
prices[toPick].second = emoticons[toPick] * sale[i] / 10;
pick(users, emoticons, prices, toPick + 1);
}
}
vector<int> solution(vector<vector<int>> users, vector<int> emoticons) {
vector<int> answer;
vector<pii> prices(emoticons.size(), {0, 0});
pick(users, emoticons, prices, 0);
answer.push_back(ans.first);
answer.push_back(ans.second);
return answer;
}
#ifndef ONLINE_JUDGE
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
return 0;
}
#endif
4번
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename a, typename b>
ostream& operator<<(ostream& os, const pair<a, b>& pai) {
os << pai.first << ' ' << pai.second;
return os;
}
template<typename a, typename b>
istream& operator>>(istream& is, pair<a, b>& pai) {
is >> pai.first >> pai.second;
return is;
}
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
#define all(x) (x).begin(), (x).end()
#define INF (INT_MAX / 2)
#define MAX_N 10'005
#define MOD 1'000'000'007
bool ans;
vector<ll> binVal;
deque<int> calcBin(ll v) {
deque<int> ret;
while(v) {
ret.emplace_front(v % 2);
v /= 2;
}
return ret;
}
bool check(deque<int>& arr, int l, int r) {
int mid = (l + r) / 2;
assert(l <= r);
if (l == r) {
return arr[mid];
}
bool lexpect = check(arr, l, mid - 1);
bool rexpect = check(arr, mid + 1, r);
if ((lexpect || rexpect) && !arr[mid]) {
ans = false;
}
return arr[mid];
}
vector<int> solution(vector<long long> numbers) {
vector<int> answer;
binVal.emplace_back(0);
for (int i = 1; i <= 60; ++i) {
binVal.emplace_back((binVal.back() + 1) * 2 - 1);
}
for (ll number : numbers) {
ans = true;
deque<int> arr = calcBin(number);
int h = lower_bound(all(binVal), arr.size()) - binVal.begin();
for (int i = 0; i < arr.size() - binVal[h]; ++i)
arr.emplace_front(0);
// bool heightCheck = false;
// for (int i = 0; i < arr.size(); i += 2) {
// if (arr[i] == 1) heightCheck = true;
// }
// if (!heightCheck) {
// ans = false;
// }
check(arr, 0, arr.size() - 1);
answer.emplace_back(ans);
}
return answer;
}
#ifndef ONLINE_JUDGE
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
vector<ll> in;
for (int i = 1; i <= 100000; ++i)
in.emplace_back(i);
auto v = solution(in);
for (int i = 1; i <= v.size(); ++i)
cout << i << ": " << v[i - 1] << endl;
return 0;
}
#endif
5번
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename a, typename b>
ostream& operator<<(ostream& os, const pair<a, b>& pai) {
os << pai.first << ' ' << pai.second;
return os;
}
template<typename a, typename b>
istream& operator>>(istream& is, pair<a, b>& pai) {
is >> pai.first >> pai.second;
return is;
}
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
#define all(x) (x).begin(), (x).end()
#define INF (INT_MAX / 2)
#define MAX_N 55
#define MOD 1'000'000'007
string arr[MAX_N][MAX_N];
int parent[MAX_N * MAX_N];
int find(int u){
if (u == parent[u]) return u;
return parent[u] = find(parent[u]);
}
void merge(int u, int v) {
u = find(u);
v = find(v);
if (arr[u / MAX_N][u % MAX_N].size() && arr[v / MAX_N][v % MAX_N].size()) {
parent[v] = u;
} else if (arr[u / MAX_N][u % MAX_N].size()) {
parent[v] = u;
} else {
parent[u] = v;
}
}
vector<string> solution(vector<string> commands) {
for (int i = 0; i < MAX_N * MAX_N; ++i)
parent[i] = i;
vector<string> answer;
for (auto& str : commands) {
string query = str.substr(0, str.find(' '));
str.erase(0, str.find(' ') + 1);
if (!query.compare("UPDATE")) {
string s1 = str.substr(0, str.find(' '));
str.erase(0, str.find(' ') + 1);
bool check = str.find(' ') == string::npos;
string s2 = str.substr(0, str.find(' '));
str.erase(0, str.find(' ') + 1);
if (check) {
for (int i = 0; i < MAX_N; ++i) {
for (int j = 0; j < MAX_N; ++j) {
int v = find(i * MAX_N + j);
if (!arr[v / MAX_N][v % MAX_N].compare(s1)) {
arr[v / MAX_N][v % MAX_N] = s2;
}
}
}
} else {
string s3 = str;
int r = atoi(s1.c_str());
int c = atoi(s2.c_str());
int v = find(r * MAX_N + c);
arr[v / MAX_N][v % MAX_N] = s3;
}
} else if (!query.compare("MERGE")) {
int r1 = atoi(str.substr(0, str.find(' ')).c_str());
str.erase(0, str.find(' ') + 1);
int c1 = atoi(str.substr(0, str.find(' ')).c_str());
str.erase(0, str.find(' ') + 1);
int r2 = atoi(str.substr(0, str.find(' ')).c_str());
str.erase(0, str.find(' ') + 1);
int c2 = atoi(str.substr(0, str.find(' ')).c_str());
str.erase(0, str.find(' ') + 1);
int v1 = r1 * MAX_N + c1;
int v2 = r2 * MAX_N + c2;
merge(v1, v2);
} else if (!query.compare("UNMERGE")) {
int r = atoi(str.substr(0, str.find(' ')).c_str());
str.erase(0, str.find(' ') + 1);
int c = atoi(str.substr(0, str.find(' ')).c_str());
str.erase(0, str.find(' ') + 1);
int num = find(r * MAX_N + c);
string temp = arr[num / MAX_N][num % MAX_N];
for (int i = 0; i < MAX_N; ++i) {
for (int j = 0; j < MAX_N; ++j) {
find(i * MAX_N + j);
}
}
for (int i = 0; i < MAX_N; ++i) {
for (int j = 0; j < MAX_N; ++j) {
int v = i * MAX_N + j;
if (find(v) == num) {
arr[i][j].clear();
parent[v] = v;
}
}
}
arr[r][c] = temp;
} else if (!query.compare("PRINT")) {
int r = atoi(str.substr(0, str.find(' ')).c_str());
str.erase(0, str.find(' ') + 1);
int c = atoi(str.substr(0, str.find(' ')).c_str());
str.erase(0, str.find(' ') + 1);
int v = find(r * MAX_N + c);
if (arr[v / MAX_N][v % MAX_N].empty()) answer.emplace_back("EMPTY");
else answer.emplace_back(arr[v / MAX_N][v % MAX_N]);
}
// for (int i = 1; i <= 4; ++i,cout<<endl)
// for (int j = 1; j <= 4; ++j)
// cout << arr[find(i * MAX_N + j) / MAX_N][find(i * MAX_N + j) % MAX_N] << ' ';
// cout << endl;
}
return answer;
}
#ifndef ONLINE_JUDGE
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
return 0;
}
#endif
6번
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename a, typename b>
ostream& operator<<(ostream& os, const pair<a, b>& pai) {
os << pai.first << ' ' << pai.second;
return os;
}
template<typename a, typename b>
istream& operator>>(istream& is, pair<a, b>& pai) {
is >> pai.first >> pai.second;
return is;
}
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
#define all(x) (x).begin(), (x).end()
#define INF (INT_MAX / 2)
#define MAX_N 10'005
#define MOD 1'000'000'007
int calcDist(int x, int y, int r, int c) {
return abs(x - r) + abs(y - c);
}
string gotoExit(int& x, int& y, int r, int c) {
string ret;
while(x < r) {
ret.push_back('d');
++x;
}
while(y > c) {
ret.push_back('l');
--y;
}
while(y < c) {
ret.push_back('r');
++y;
}
while(x > r) {
ret.push_back('u');
--x;
}
return ret;
}
string solution(int n, int m, int x, int y, int r, int c, int k) {
string answer = "";
while(k) {
if (calcDist(x, y, r, c) == k) {
answer.append(gotoExit(x, y, r, c));
break;
}
if (calcDist(x, y, r, c) > k) {
answer = "impossible";
break;
}
if (x < n) {
answer.push_back('d');
++x;
} else if (y > 1) {
answer.push_back('l');
--y;
} else if (y < m) {
answer.push_back('r');
++y;
} else {
answer.push_back('u');
--x;
}
--k;
}
return answer;
}
#ifndef ONLINE_JUDGE
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
return 0;
}
#endif