Study/PS
20230807 업다운 랜디
피준
2023. 8. 7. 18:15
s#100.. !solved_by:p_jun *g1
30분 3문제
G1 1242 소풍 +10분 6초
이건 억까지
15분 쯤 풀이를 세우고, 25분 쯤 구현 완료해서 제출 했다
제출을 계속 하는데도 틀리거나, div by zero, overflow가 떠서
0으로 나눌 부분이 대체 어디있을지 계속 찾앗다
K가 N보다 작다면서요....
사실 예제를 안 보고 제출한 내 잘못이 크다 ㅎ
무지성 제출하는 걸 고쳐야하나
대회에선 안 그러니 괜찮을지도?
더보기
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <deque>
#include<set>
#include<map>
#include<cassert>
using namespace std;
using ll = long long;
#define MOD 1000000007
const ll INF = 987654321;
const int MX = 500005;
int main() {
ios::sync_with_stdio(0); cin.tie(0), cout.tie(0);
int n, k, m; cin >> n >> k >> m;
int cnt = 1;
int move = k % n ? k % n : n;
while (1) {
if (m == move) break;
if (m > move) m -= move;
else m += n - move;
cnt++;
n--;
move = k % n ? k % n : n;
}
cout << cnt << '\n';
}
G2 1112 진법 변환 -11분 20초
그냥 평소처럼 계산해서 될거 같아서
그냥 구현하고 맞았다
더보기
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <deque>
#include<set>
#include<map>
#include<cassert>
using namespace std;
using ll = long long;
#define MOD 1000000007
const ll INF = 987654321;
const int MX = 500005;
int main() {
ios::sync_with_stdio(0); cin.tie(0), cout.tie(0);
int x;
int b;
cin >> x >> b;
int m = 0;
if (b > 0 && x < 0) m = 1, x = -x;
string ans = "";
while (x) {
int r = x % b;
x = x / b;
if (r < 0) {
x++;
r -= b;
}
ans += to_string(r);
}
reverse(ans.begin(), ans.end());
if (ans == "") cout << 0 << '\n';
else {
if (m) cout << '-';
cout << ans << '\n';
}
}
G1 1736 쓰레기 치우기 -8분 30초
ICPC2021에 참가 할 때 만난 23248 Treasure Hunter의 쉬운 버전이다
LIS 풀이가 기억나 구현했다
더보기
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <deque>
#include<set>
#include<map>
#include<cassert>
using namespace std;
using ll = long long;
#define MOD 1000000007
const ll INF = 987654321;
const int MX = 500005;
bool cmp(pair<int, int>& a, pair<int, int>& b) {
if (a.first == b.first) return a.second > b.second;
return a.first > b.first;
}
int main() {
ios::sync_with_stdio(0); cin.tie(0), cout.tie(0);
int r, c; cin >> r >> c;
vector<pair<int, int>> v;
for (int i = 0; i < r; i++) for (int j = 0; j < c; j++) {
int k; cin >> k;
if (k == 1) v.push_back({ i,j });
}
sort(v.begin(), v.end(), cmp);
vector<int> l;
for (auto& [x,y]:v) {
if (l.empty() || l.back() < y) l.push_back(y);
else {
int pos = lower_bound(l.begin(), l.end(), y) - l.begin();
l[pos] = y;
}
}
cout << l.size() << endl;
}