From 5d47b9ad77ba122041cef010e416c722cdc3cef9 Mon Sep 17 00:00:00 2001 From: jmseo1204 Date: Tue, 1 Feb 2022 22:43:39 +0900 Subject: [PATCH 1/2] 220201 --- BJ_1062_jmseo1204.cpp | 219 ++++++++++++++++++++++++++++++++++++++++++ BJ_1103_jmseo1204.cpp | 179 ++++++++++++++++++++++++++++++++++ BJ_1107_jmseo1204.cpp | 201 ++++++++++++++++++++++++++++++++++++++ BJ_1234_jmseo1204.cpp | 207 +++++++++++++++++++++++++++++++++++++++ BJ_4902_jmseo1204.cpp | 179 ++++++++++++++++++++++++++++++++++ 5 files changed, 985 insertions(+) create mode 100644 BJ_1062_jmseo1204.cpp create mode 100644 BJ_1103_jmseo1204.cpp create mode 100644 BJ_1107_jmseo1204.cpp create mode 100644 BJ_1234_jmseo1204.cpp create mode 100644 BJ_4902_jmseo1204.cpp diff --git a/BJ_1062_jmseo1204.cpp b/BJ_1062_jmseo1204.cpp new file mode 100644 index 0000000..124995b --- /dev/null +++ b/BJ_1062_jmseo1204.cpp @@ -0,0 +1,219 @@ +#include +//#include +#define INF 987654321 +#define MIN 1e-10 +#define HASHNUM 37813 +#define endl '\n' +#define intA 65 +#define MOD 100000007 +using namespace std; +using ll = long long; +template +using matrix = vector >; +template +using cube = vector >; +using uint = unsigned int; +using VI = vector; +using VLL = vector; +using P = pair; +using PLL = pair; +using VPLL = vector; +using VP = vector >; +template +class three{ +public: + T1 a; + T2 b; + T3 c; + three(T1&& x, T2&& y, T3&& z){ + a=x; + b=y; + c=z; + } + three(){ + a= 0; + b= 0; + c= 0; + } +}; +using T = three; +using VT = vector; +template +ostream& operator <<(ostream& os, three& p){ + return os << "(" << p.a <<" "< +istream& operator >>(istream& is, three& p) { + return is >> p.a >> p.b >> p.c; +} +template +class four{ +public: + T1 a; + T2 b; + T3 c; + T4 d; + four(T1 x, T2 y, T3 z, T4 w){ + a=x; + b=y; + c=z; + d=w; + } + four(){ + a= 0; + b= 0; + c= 0; + d= 0; + } +}; +using F = four; +using VF = vector; +template +ostream& operator <<(ostream& os, four& p){ + return os << "(" << p.a <<" "< +istream& operator >>(istream& is, four& p){ + return is >> p.a >> p.b >> p.c >> p.d; +} +template +ostream& operator<<(ostream& os, pair& a){ + return os << "("< +istream& operator>>(istream& is, pair& a){ + return is >> a.first >> a.second; +} +template +ostream& operator <<(ostream& os, matrix& arr){ + for(int i=0; i +istream& operator >>(istream& is, matrix& arr){ + for(int i=0; i> arr[i][j]; + return is; +} +template +ostream& operator <<(ostream& os, vector& arr){ + for(int i=0; i +istream& operator >>(istream& is, vector& arr){ + for(int i=0; i> arr[i]; + return is; +} +template +ostream& operator << (ostream& os, list& arr){ + for(auto i : arr){ + os << i << ' '; + } + return os; +} +int ulim(int a, int bound){ + return a>bound ? bound : a; +} + +template +double abs(pair a){return sqrt(pow(a.first, 2)+pow(a.second, 2));} + +template +ostream& operator << (ostream& os, stack& arr){ + while(!arr.empty()){ + auto i = arr.top(); + arr.pop(); + os << i << ' '; + } + return os; +} + + +int DFS(matrix& arr, matrix& dp, matrix& travel, int r, int c){ + int N = arr.size(); + int M = arr[0].size(); + if(r<0 || r>=N || c<0 || c>=M || arr[r][c]==0) return 0; + else if(travel[r][c]) return INF; + int& ret = dp[r][c]; + if(ret!=-1) return ret; + travel[r][c] = true; + int Max = 0; + for(int i=-1; i<=1; i++){ + for(int j=-1; j<=1; j++){ + if((i+j+2)%2==0) continue; + Max = max(Max, DFS(arr, dp, travel, r+i*arr[r][c], c+j*arr[r][c])); + } + } + travel[r][c] = false; + return ret = Max+1; +} + +int bitCount(uint a){ + int ret = 0; + while(a>0){ + ret += a&1; + a >>= 1; + } + return ret; +} + +int DFS(vector& arr, uint travel, uint now, int K){ + if(bitCount(now)==K || travel == 0){ + int ret=0; + for(uint& i : arr){ + ret += (i & now) == i; + } + return ret; + } + int p= ceil(log2(now+0.6)); + int mx = 0; + while(travel>0){ + if(travel & 1<> N >> K; + if(K<5){cout << 0; return 0;} + K-=5; + vector arr(N); + uint travel=0; + vector have(26); + have['a'-'a'] = true; + have['n'-'a'] = true; + have['t'-'a'] = true; + have['i'-'a'] = true; + have['c'-'a'] = true; + for(int i=0; i> temp; + uint key=0; + for(int j=4; j +//#include +#define INF 987654321 +#define MIN 1e-10 +#define HASHNUM 37813 +#define endl '\n' +#define intA 65 +#define MOD 100000007 +using namespace std; +using ll = long long; +template +using matrix = vector >; +template +using cube = vector >; +using uint = unsigned int; +using VI = vector; +using VLL = vector; +using P = pair; +using PLL = pair; +using VPLL = vector; +using VP = vector >; +template +class three{ +public: + T1 a; + T2 b; + T3 c; + three(T1&& x, T2&& y, T3&& z){ + a=x; + b=y; + c=z; + } + three(){ + a= 0; + b= 0; + c= 0; + } +}; +using T = three; +using VT = vector; +template +ostream& operator <<(ostream& os, three& p){ + return os << "(" << p.a <<" "< +istream& operator >>(istream& is, three& p) { + return is >> p.a >> p.b >> p.c; +} +template +class four{ +public: + T1 a; + T2 b; + T3 c; + T4 d; + four(T1 x, T2 y, T3 z, T4 w){ + a=x; + b=y; + c=z; + d=w; + } + four(){ + a= 0; + b= 0; + c= 0; + d= 0; + } +}; +using F = four; +using VF = vector; +template +ostream& operator <<(ostream& os, four& p){ + return os << "(" << p.a <<" "< +istream& operator >>(istream& is, four& p){ + return is >> p.a >> p.b >> p.c >> p.d; +} +template +ostream& operator<<(ostream& os, pair& a){ + return os << "("< +istream& operator>>(istream& is, pair& a){ + return is >> a.first >> a.second; +} +template +ostream& operator <<(ostream& os, matrix& arr){ + for(int i=0; i +istream& operator >>(istream& is, matrix& arr){ + for(int i=0; i> arr[i][j]; + return is; +} +template +ostream& operator <<(ostream& os, vector& arr){ + for(int i=0; i +istream& operator >>(istream& is, vector& arr){ + for(int i=0; i> arr[i]; + return is; +} +template +ostream& operator << (ostream& os, list& arr){ + for(auto i : arr){ + os << i << ' '; + } + return os; +} +int ulim(int a, int bound){ + return a>bound ? bound : a; +} + +template +double abs(pair a){return sqrt(pow(a.first, 2)+pow(a.second, 2));} + +template +ostream& operator << (ostream& os, stack& arr){ + while(!arr.empty()){ + auto i = arr.top(); + arr.pop(); + os << i << ' '; + } + return os; +} + + +int DFS(matrix& arr, matrix& dp, matrix& travel, int r, int c){ + int N = arr.size(); + int M = arr[0].size(); + if(r<0 || r>=N || c<0 || c>=M || arr[r][c]==0) return 0; + else if(travel[r][c]) return INF; + int& ret = dp[r][c]; + if(ret!=-1) return ret; + travel[r][c] = true; + int Max = 0; + for(int i=-1; i<=1; i++){ + for(int j=-1; j<=1; j++){ + if((i+j+2)%2==0) continue; + Max = max(Max, DFS(arr, dp, travel, r+i*arr[r][c], c+j*arr[r][c])); + } + } + travel[r][c] = false; + return ret = Max+1; +} + +int main(){ + cin.tie(nullptr); + cout.tie(nullptr); + ios_base::sync_with_stdio(false); + int N, M; + cin >> N >> M; + matrix arr(N, VI(M)); + matrix travel(N, vector(M)); + matrix dp(N, VI(M, -1)); + for(int i=0; i> temp; + arr[i][j] = temp == 'H' ? 0 : (temp -'0'); + } + } + int ret = DFS(arr, dp, travel, 0, 0); + cout << (ret >= INF ? -1 : ret); + +} + + diff --git a/BJ_1107_jmseo1204.cpp b/BJ_1107_jmseo1204.cpp new file mode 100644 index 0000000..d88c20b --- /dev/null +++ b/BJ_1107_jmseo1204.cpp @@ -0,0 +1,201 @@ +#include +//#include +#define INF 987654321 +#define MIN 1e-10 +#define HASHNUM 37813 +#define endl '\n' +#define intA 65 +#define MOD 1000000007 +using namespace std; +using ll = long long; +template +using matrix = vector >; +template +using cube = vector >; +using uint = unsigned int; +using VI = vector; +using VLL = vector; +using P = pair; +using VP = vector >; +template +class three{ +public: + T1 a; + T2 b; + T3 c; + three(T1&& x, T2&& y, T3&& z){ + a=x; + b=y; + c=z; + } + three(){ + a= 0; + b= 0; + c= 0; + } +}; +using T = three; +using VT = vector; +template +ostream& operator <<(ostream& os, three& p){ + return os << "(" << p.a <<" "< +istream& operator >>(istream& is, three& p) { + return is >> p.a >> p.b >> p.c; +} +template +class four{ +public: + T1 a; + T2 b; + T3 c; + T4 d; + four(T1 x, T2 y, T3 z, T4 w){ + a=x; + b=y; + c=z; + d=w; + } + four(){ + a= 0; + b= 0; + c= 0; + d= 0; + } +}; +using F = four; +using VF = vector; +template +ostream& operator <<(ostream& os, four& p){ + return os << "(" << p.a <<" "< +istream& operator >>(istream& is, four& p){ + return is >> p.a >> p.b >> p.c >> p.d; +} +template +T Max(T a, T b){ + return less()(a, b) ? b : a; +} +template +T Min(T a, T b){ + return less()(a, b) ? a : b; +} +template +T abs(T a){ + return a > 0 ? a : -a; +} +int bitCount(uint bit){ + int cnt = 0; + while(bit){ + cnt += bit & 1; + bit >>= 1; + } + return cnt; +} +template +ostream& operator<<(ostream& os, pair& a){ + return os << "("< +istream& operator>>(istream& is, pair& a){ + return is >> a.first >> a.second; +} +template +ostream& operator <<(ostream& os, matrix& arr){ + for(int i=0; i +istream& operator >>(istream& is, matrix& arr){ + for(int i=0; i> arr[i][j]; + return is; +} +template +ostream& operator <<(ostream& os, vector& arr){ + for(int i=0; i +istream& operator >>(istream& is, vector& arr){ + for(int i=0; i> arr[i]; + return is; +} +template +ostream& operator << (ostream& os, list& arr){ + for(auto i : arr){ + os << i << ' '; + } + return os; +} + +int ulim(int a, int bound){ + return a>bound ? bound : a; +} + +int recur(matrix& candid, string& str, int make, int p, int cnt){ + int num = stoi(str); + if(p==str.size()) return make == 0 ? (1+num) : (abs(make-num)+cnt); + VI& arr = candid[p]; + int min = abs(num-100); + for(int i : arr){ + int ret = recur(candid, str, make*10+i, p+1, cnt+(i>9? 2 : 1)); + min = Min(min, ret); + } + if(p==0 && str.size()>1) min = Min(min, recur(candid, str, make, p+1, cnt)); + return min; +} + +int main(){ + cin.tie(nullptr); + cout.tie(nullptr); + ios_base::sync_with_stdio(false); + string N; + cin >> N; + int M; + cin >> M; + VI del(M); + cin >> del; + VI arr; + for(int i=0; i<=9; i++){ + bool canPush = true; + for(int j : del){ + if(i==j){ + canPush = false; + break; + } + } + if(canPush) arr.push_back(i); + } + + int leng = N.length(); + if(arr.size()==0){ + cout << abs(stoi(N)-100); + return 0; + }else if (arr.front()==0 && arr.size()==1) { + int num = stoi(N); + cout << Min(abs(num-100), num+1); + return 0; + } + + + int min = arr.front(); + matrix candid(leng, arr); + if(min == 0) candid[0].push_back(arr[1]*10); + else candid[0].push_back(min*11); + int cnt=0; + int delta = recur(candid, N, 0, 0, cnt); + cout << delta; + + return 0; +} + + diff --git a/BJ_1234_jmseo1204.cpp b/BJ_1234_jmseo1204.cpp new file mode 100644 index 0000000..fe468db --- /dev/null +++ b/BJ_1234_jmseo1204.cpp @@ -0,0 +1,207 @@ +#include +//#include +#define INF 987654321 +#define MIN 1e-10 +#define HASHNUM 37813 +#define endl '\n' +#define intA 65 +#define MOD 100000007 +using namespace std; +using ll = long long; +template +using matrix = vector >; +template +using cube = vector >; +using uint = unsigned int; +using VI = vector; +using VLL = vector; +using P = pair; +using PLL = pair; +using VPLL = vector; +using VP = vector >; +template +class three{ +public: + T1 a; + T2 b; + T3 c; + three(T1&& x, T2&& y, T3&& z){ + a=x; + b=y; + c=z; + } + three(){ + a= 0; + b= 0; + c= 0; + } +}; +using T = three; +using VT = vector; +template +ostream& operator <<(ostream& os, three& p){ + return os << "(" << p.a <<" "< +istream& operator >>(istream& is, three& p) { + return is >> p.a >> p.b >> p.c; +} +template +class four{ +public: + T1 a; + T2 b; + T3 c; + T4 d; + four(T1 x, T2 y, T3 z, T4 w){ + a=x; + b=y; + c=z; + d=w; + } + four(){ + a= 0; + b= 0; + c= 0; + d= 0; + } +}; +using F = four; +using VF = vector; +template +ostream& operator <<(ostream& os, four& p){ + return os << "(" << p.a <<" "< +istream& operator >>(istream& is, four& p){ + return is >> p.a >> p.b >> p.c >> p.d; +} +template +ostream& operator<<(ostream& os, pair& a){ + return os << "("< +istream& operator>>(istream& is, pair& a){ + return is >> a.first >> a.second; +} +template +ostream& operator <<(ostream& os, matrix& arr){ + for(int i=0; i +istream& operator >>(istream& is, matrix& arr){ + for(int i=0; i> arr[i][j]; + return is; +} +template +ostream& operator <<(ostream& os, vector& arr){ + for(int i=0; i +istream& operator >>(istream& is, vector& arr){ + for(int i=0; i> arr[i]; + return is; +} +template +ostream& operator << (ostream& os, list& arr){ + for(auto i : arr){ + os << i << ' '; + } + return os; +} +int ulim(int a, int bound){ + return a>bound ? bound : a; +} + +template +double abs(pair a){return sqrt(pow(a.first, 2)+pow(a.second, 2));} + +template +ostream& operator << (ostream& os, stack& arr){ + while(!arr.empty()){ + auto i = arr.top(); + arr.pop(); + os << i << ' '; + } + return os; +} + + + + +int bitCount(uint a){ + int ret = 0; + while(a>0){ + ret += a&1; + a >>= 1; + } + return ret; +} + +ll getDP(cube& dp, int a, int b, int c){ + if(a<0 || b<0 || c<0) return 0; + return dp[a][b][c]; +} +void setDP(cube& dp, int a, int b, int c, int v){ + int A = dp.size(); + int B = dp[0].size(); + int C = dp[0][0].size(); + if(a>=A || b>=B || c>=C) return; + dp[a][b][c] = v; +} + +int main(){ + cin.tie(nullptr); + cout.tie(nullptr); + ios_base::sync_with_stdio(false); + int N, A, B, C; + cin >> N >> A >> B >> C; + vector > dp(2, cube(A+1, matrix(B+1, VLL(C+1, 3)))); + matrixbino(N+1, VLL(N+1)); + for(int i=0; i<=N; i++){ + for(int j=0; j<=i; j++){ + bino[i][j] = j==0 ? 1 : bino[i-1][j-1]+bino[i-1][j]; + } + } + + + setDP(dp[1], 0, 0, 0, 0); + for(int i=1; i<=A; i++) setDP(dp[1], i, 0, 0, 1); + for(int i=1; i<=B; i++) setDP(dp[1], 0, i, 0, 1); + for(int i=1; i<=C; i++) setDP(dp[1], 0, 0, i, 1); + + for(int i=1; i<=A; i++) for(int j=1; j<=B; j++) setDP(dp[1], i, j, 0, 2); + for(int i=1; i<=B; i++) for(int j=1; j<=C; j++) setDP(dp[1], 0, i, j, 2); + for(int i=1; i<=C; i++) for(int j=1; j<=A; j++) setDP(dp[1], j, 0, i, 2); + + for(int i=2; i<=N; i++){ + for(int a=0; a<=A; a++){ + for(int b=0; b<=B; b++){ + for(int c=0; c<=C; c++){ + dp[i%2][a][b][c]=getDP(dp[(i-1)%2], a-i, b, c)+getDP(dp[(i-1)%2], a, b-i, c)+getDP(dp[(i-1)%2], a, b, c-i); + if(i%2==0){ + ll rate = bino[i][i/2]; + dp[i%2][a][b][c]+=rate*getDP(dp[(i-1)%2], a-i/2, b-i/2, c); + dp[i%2][a][b][c]+=rate*getDP(dp[(i-1)%2], a, b-i/2, c-i/2); + dp[i%2][a][b][c]+=rate*getDP(dp[(i-1)%2], a-i/2, b, c-i/2); + } + if(i%3==0){ + ll rate = bino[i][i/3]*bino[i*2/3][i/3]; + dp[i%2][a][b][c]+=rate*getDP(dp[(i-1)%2], a-i/3, b-i/3, c-i/3); + } + } + } + } + } + cout << dp[N%2][A][B][C]; +} + diff --git a/BJ_4902_jmseo1204.cpp b/BJ_4902_jmseo1204.cpp new file mode 100644 index 0000000..5d54c82 --- /dev/null +++ b/BJ_4902_jmseo1204.cpp @@ -0,0 +1,179 @@ +#include +//#include +#define INF 987654321 +#define MIN 1e-10 +#define HASHNUM 37813 +#define endl '\n' +#define intA 65 +#define MOD 100000007 +using namespace std; +using ll = long long; +template +using matrix = vector >; +template +using cube = vector >; +using uint = unsigned int; +using VI = vector; +using VLL = vector; +using P = pair; +using PLL = pair; +using VPLL = vector; +using VP = vector >; +template +class three{ +public: + T1 a; + T2 b; + T3 c; + three(T1&& x, T2&& y, T3&& z){ + a=x; + b=y; + c=z; + } + three(){ + a= 0; + b= 0; + c= 0; + } +}; +using T = three; +using VT = vector; +template +ostream& operator <<(ostream& os, three& p){ + return os << "(" << p.a <<" "< +istream& operator >>(istream& is, three& p) { + return is >> p.a >> p.b >> p.c; +} +template +class four{ +public: + T1 a; + T2 b; + T3 c; + T4 d; + four(T1 x, T2 y, T3 z, T4 w){ + a=x; + b=y; + c=z; + d=w; + } + four(){ + a= 0; + b= 0; + c= 0; + d= 0; + } +}; +using F = four; +using VF = vector; +template +ostream& operator <<(ostream& os, four& p){ + return os << "(" << p.a <<" "< +istream& operator >>(istream& is, four& p){ + return is >> p.a >> p.b >> p.c >> p.d; +} +template +ostream& operator<<(ostream& os, pair& a){ + return os << "("< +istream& operator>>(istream& is, pair& a){ + return is >> a.first >> a.second; +} +template +ostream& operator <<(ostream& os, matrix& arr){ + for(int i=0; i +istream& operator >>(istream& is, matrix& arr){ + for(int i=0; i> arr[i][j]; + return is; +} +template +ostream& operator <<(ostream& os, vector& arr){ + for(int i=0; i +istream& operator >>(istream& is, vector& arr){ + for(int i=0; i> arr[i]; + return is; +} +template +ostream& operator << (ostream& os, list& arr){ + for(auto i : arr){ + os << i << ' '; + } + return os; +} +int ulim(int a, int bound){ + return a>bound ? bound : a; +} + +template +double abs(pair a){return sqrt(pow(a.first, 2)+pow(a.second, 2));} + +template +ostream& operator << (ostream& os, stack& arr){ + while(!arr.empty()){ + auto i = arr.top(); + arr.pop(); + os << i << ' '; + } + return os; +} + + +int main(){ + //cin.tie(nullptr); + cout.tie(nullptr); + ios_base::sync_with_stdio(false); + int cnt = 0; + while(true){ + int N; + cin >> N; + if(N==0) break; + cnt++; + matrix arr(N); + matrix psum(N); + cube dp(2, matrix(N, VI(2*N+1, -INF))); + int M = -INF; + for(int i=0; i> arr[i][j]; + M = max(M, arr[i][j]); + dp[1][i][j] = arr[i][j]; + psum[i][j+1] = arr[i][j] + psum[i][j]; + } + } + for(int k=2; k<=N; k++){ + for(int i=0; i=2*k-1 && 2*k-1<=j && j<=2*i-(2*k-1)){ + dp[k%2][i][j] = dp[(k-1)%2][i][j] + psum[i-(k-1)][j+1] - psum[i-(k-1)][j+1-(2*k-1)]; + M = max(M, dp[k%2][i][j]); + } + } + } + } + cout < Date: Thu, 10 Feb 2022 03:12:41 +0900 Subject: [PATCH 2/2] 220210 --- 3. Greedy/BJ_1041_jmseo1204.cpp | 28 ++++++++ 3. Greedy/BJ_1045_jmseo1204.cpp | 115 +++++++++++++++++++++++++++++++ 3. Greedy/BJ_1092_jmseo1204.cpp | 35 ++++++++++ 3. Greedy/BJ_14698_jmseo1204.cpp | 98 ++++++++++++++++++++++++++ 3. Greedy/BJ_1715_jmseo1204.cpp | 94 +++++++++++++++++++++++++ 5 files changed, 370 insertions(+) create mode 100644 3. Greedy/BJ_1041_jmseo1204.cpp create mode 100644 3. Greedy/BJ_1045_jmseo1204.cpp create mode 100644 3. Greedy/BJ_1092_jmseo1204.cpp create mode 100644 3. Greedy/BJ_14698_jmseo1204.cpp create mode 100644 3. Greedy/BJ_1715_jmseo1204.cpp diff --git a/3. Greedy/BJ_1041_jmseo1204.cpp b/3. Greedy/BJ_1041_jmseo1204.cpp new file mode 100644 index 0000000..018b810 --- /dev/null +++ b/3. Greedy/BJ_1041_jmseo1204.cpp @@ -0,0 +1,28 @@ +#include +using namespace std; +using VI = vector; +int main(){ + long long N; + cin >> N; + VI arr(6); + int maxx=0; + int sum=0; + for(int& i : arr){ + cin >> i; + maxx = max(maxx, i); + sum+=i; + } + + if(N==1) { + cout << sum-maxx; + return 0; + } + int m1 = min(arr[0], arr[5]); + int m2 = min(arr[1], arr[4]); + int m3 = min(arr[2], arr[3]); + int min1 = min(m1, min(m2, m3)); + int max1 = max(m1, max(m2, m3)); + long long ret = (5*N-6)*(N-2)*min1+4*(2*N-3)*(m1+m2+m3-max1)+4*(m1+m2+m3); + cout << ret; + return 0; + } diff --git a/3. Greedy/BJ_1045_jmseo1204.cpp b/3. Greedy/BJ_1045_jmseo1204.cpp new file mode 100644 index 0000000..088e201 --- /dev/null +++ b/3. Greedy/BJ_1045_jmseo1204.cpp @@ -0,0 +1,115 @@ +#include +//#include +#define INF 1987654321 +#define MIN 1e-10 +#define endl '\n' +#define MOD 1000000007 +#define ALL(x) begin(x),end(x) +using namespace std; +using ll = long long; +template +using matrix = vector >; +template +using cube = vector >; +using uint = unsigned int; +using VI = vector; +using VB = vector; +using VLL = vector; +using P = pair; +using PLL = pair; +using VPLL = vector; +using VP = vector >; + + +template +ostream& operator<<(ostream& os, pair& a){ + return os << "("< +istream& operator>>(istream& is, pair& a){ + return is >> a.first >> a.second; +} +template +ostream& operator <<(ostream& os, matrix& arr){ + for(int i=0; i +istream& operator >>(istream& is, matrix& arr){ + for(int i=0; i> arr[i][j]; + return is; +} +template +ostream& operator <<(ostream& os, vector& arr){ + for(int i=0; i +istream& operator >>(istream& is, vector& arr){ + for(int i=0; i> arr[i]; + return is; +} +template +ostream& operator << (ostream& os, list& arr){ + for(auto i : arr){ + os << i << ' '; + } + return os; +} + + +template +double abs(pair a){return sqrt(pow(a.first, 2)+pow(a.second, 2));} +ll max(ll a, ll b){return a>b ? a : b;} + + +int main(){ + cin.tie(nullptr)->ios_base::sync_with_stdio(false); + int N, M; + cin >> N >> M; + matrix adj(N, vector(N)); + disjoint_set ds(N); + VI ret(N); + int cnt = M-(N-1); + for(int i=0; i> temp; + for(int j=i; j0){ + ret[i]++; + ret[j]++; + cnt--; + } + } + } + if(cnt!=0) { + cout << -1; + }else{ + for(int i : ret) cout << i <<' '; + } + } + +} + diff --git a/3. Greedy/BJ_1092_jmseo1204.cpp b/3. Greedy/BJ_1092_jmseo1204.cpp new file mode 100644 index 0000000..b1c3102 --- /dev/null +++ b/3. Greedy/BJ_1092_jmseo1204.cpp @@ -0,0 +1,35 @@ +int main(){ + cin.tie(nullptr)->ios_base::sync_with_stdio(false); + int N; + cin >> N; + VI crane(N); + cin >> crane; + sort(ALL(crane)); + int M; + cin >> M; + VI box(M); + cin >> box; + sort(ALL(box)); + VI startidx(N, M-1); + vector travel(M); + int boxcnt = 0; + int clockcnt = 0; + while(!(boxcnt==M || clockcnt==M)){ + clockcnt++; + for(int i=N-1; i>=0; i--){ + for(int j=startidx[i]; j>=0; j--){ + if((!travel[j]) && box[j]<=crane[i]){ + travel[j] = true; + boxcnt++; + startidx[i] = j-1; + break; + } + if(j==0) startidx[i] = -1; + } + } + } + //cout << boxcnt << endl << clockcnt << endl << travel < +//#include +#define INF 1987654321 +#define MIN 1e-10 +#define endl '\n' +#define MOD 1000000007 +#define ALL(x) begin(x),end(x) +using namespace std; +using ll = long long; +template +using matrix = vector >; +template +using cube = vector >; +using uint = unsigned int; +using VI = vector; +using VB = vector; +using VLL = vector; +using P = pair; +using PLL = pair; +using VPLL = vector; +using VP = vector >; + + +template +ostream& operator<<(ostream& os, pair& a){ + return os << "("< +istream& operator>>(istream& is, pair& a){ + return is >> a.first >> a.second; +} +template +ostream& operator <<(ostream& os, matrix& arr){ + for(int i=0; i +istream& operator >>(istream& is, matrix& arr){ + for(int i=0; i> arr[i][j]; + return is; +} +template +ostream& operator <<(ostream& os, vector& arr){ + for(int i=0; i +istream& operator >>(istream& is, vector& arr){ + for(int i=0; i> arr[i]; + return is; +} +template +ostream& operator << (ostream& os, list& arr){ + for(auto i : arr){ + os << i << ' '; + } + return os; +} + + +template +double abs(pair a){return sqrt(pow(a.first, 2)+pow(a.second, 2));} +ll max(ll a, ll b){return a>b ? a : b;} + + +int main(){ + cin.tie(nullptr)->ios_base::sync_with_stdio(false); + int T; + cin >> T; + for(int t=0; t> N; + priority_queue > pq; + VLL ret(N-1); + for(int i=0; i> temp; + pq.push(temp); + } + for(int i=0; ill{return a*(b%MOD)%MOD;}) << endl; + } +} + diff --git a/3. Greedy/BJ_1715_jmseo1204.cpp b/3. Greedy/BJ_1715_jmseo1204.cpp new file mode 100644 index 0000000..c6cf6f8 --- /dev/null +++ b/3. Greedy/BJ_1715_jmseo1204.cpp @@ -0,0 +1,94 @@ +#include +//#include +#define INF 1987654321 +#define MIN 1e-10 +#define endl '\n' +#define MOD 1000000007 +#define ALL(x) begin(x),end(x) +using namespace std; +using ll = long long; +template +using matrix = vector >; +template +using cube = vector >; +using uint = unsigned int; +using VI = vector; +using VB = vector; +using VLL = vector; +using P = pair; +using PLL = pair; +using VPLL = vector; +using VP = vector >; + + +template +ostream& operator<<(ostream& os, pair& a){ + return os << "("< +istream& operator>>(istream& is, pair& a){ + return is >> a.first >> a.second; +} +template +ostream& operator <<(ostream& os, matrix& arr){ + for(int i=0; i +istream& operator >>(istream& is, matrix& arr){ + for(int i=0; i> arr[i][j]; + return is; +} +template +ostream& operator <<(ostream& os, vector& arr){ + for(int i=0; i +istream& operator >>(istream& is, vector& arr){ + for(int i=0; i> arr[i]; + return is; +} +template +ostream& operator << (ostream& os, list& arr){ + for(auto i : arr){ + os << i << ' '; + } + return os; +} + + +template +double abs(pair a){return sqrt(pow(a.first, 2)+pow(a.second, 2));} +ll max(ll a, ll b){return a>b ? a : b;} + + +int main(){ + cin.tie(nullptr)->ios_base::sync_with_stdio(false); + int N; + cin >> N; + priority_queue > pq; + VI ret(N-1); + for(int i=0; i> temp; + pq.push(temp); + } + for(int i=0; i