Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions 06/1213.c++
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

//1. 앞 단어부터 같은 단어가 있는지 확인한다.
//2. 순서대로 vector에 저장한다. (두 개의 같은 단어 중 한 단어만)
//3. 짝지어지지 않은 단어가 한 개 이상이라면 실패한다.
//4. vector을 정렬 후 순서대로 출력 + 단어 한 개 있다면 출력 + vector를 역순으로 출력

void check_ans(string s, vector<char> ans){
for(int i=0;i<s.length();i++){
if(s[i]=='.') continue;
for(int j=i+1;j<s.length();j++){
if(s[i]==s[j]){
ans.push_back(s[i]);
s[i]=s[j]='.';
break;
}
}
}
sort(ans.begin(),ans.end());

int cnt=0;
char word;
for(int i=0;i<s.length();i++){
if(s[i]!='.') {
cnt++;
word=s[i];
}
}
if(cnt>1) cout << "I'm Sorry Hansoo";
else{
for(auto it : ans){
cout << it;
}
if(cnt==1){
cout << word;
}
for(auto it=ans.rbegin();it!=ans.rend();it++){
cout << *it;
}
}
}

int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);

string s;
cin >> s;

vector<char> ans;
check_ans(s, ans);

return 0;
}
41 changes: 41 additions & 0 deletions 06/17451.c++
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;

//1. 최소 속도값을 구하기 위해서는 뒤에서부터 봐야한다.
//2. 기준값을 잡아서 기준값보다 큰 수라면 그 수로 기준값을 업데이트한다.
//3. 기준값보다 작은 수라면 기준값보다 큰 작은 수의 배수를 계산한 후 기준값을 업데이트한다.
//4. 최종적으로 기준값에 저장된 수가 정답이 된다.


ll calc(vector<ll>& v){
ll ans=0;
for(int i=v.size()-1;i>=0;i--){ //뒤에서부터 순회
if(ans<v[i]) ans = v[i]; //기준값보다 크다면 그대로 업데이트
else{ //기준값보다 작다면 기준값보다 처음으로 큰 배수로 업데이트
ll tmp = ans/v[i];
if(ans%v[i]>0) tmp +=1;
ans = v[i]*tmp;
}
}
return ans;
}

int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);

int n;
cin >> n;

vector<ll> v(n,0);
for(int i=0;i<n;i++){
cin >> v[i];
}
cout << calc(v);

return 0;
}
69 changes: 69 additions & 0 deletions 06/18111.c++
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;
typedef pair<long long, long long> p;
const int MAX = 257;

//1. 초기의 높이값의 빈도수를 vector에 저장한다.
//2. 0부터 256까지 기준 높이를 정해, 빈도수를 저장한 vector를 사용하여 시간을 모두 구한다.
//3. 시간과 높이를 함께 저장하여 sort를 통해 조건대로 정렬한다.

bool cmp(p& p1, p& p2){
if(p1.first!=p2.first) return p1.first < p2.first;
return p1.second > p2.second;
}

p build(int block, vector<ll> height, int max){
vector<p> ans;
for(int i=0;i<=max;i++){
int b = block;
ll t=0;
for(int j=i+1;j<=max;j++){ //기준 높이보다 높다면
if(height[j]>0){
ll tmp = (j-i)*height[j];
t+=2*tmp;
b+=tmp;
}
}
for(int k=i-1;k>=0;k--){ //기준 높이보다 낮다면
if(height[k]>0){
ll tmp = (i-k)*height[k];
t+=tmp;
b-=tmp;
}
}
if(b<0) continue;
ans.push_back(make_pair(t,i));
}
sort(ans.begin(), ans.end(),cmp);
return ans[0];
}


int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);

int n,m,b;
cin >> n >> m >> b;

vector<ll> v(MAX,0);
vector<p> height;
int max=0;
while(n--){ //초기 블록 높이를 빈도수로 저장
for(int i=0;i<m;i++){
int j;
cin >> j;
if(max<j) max=j;
v[j]++;
}
}
p ans = build(b,v,max);
cout << ans.first << " " << ans.second;


return 0;