๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Algorithm ๐Ÿง‘๐Ÿป‍๐Ÿ’ป456

[๋ฐฑ์ค€,c++] 17255๋ฒˆ - N์œผ๋กœ ๋งŒ๋“ค๊ธฐ ๋ฌธ์ œ 17255๋ฒˆ: N์œผ๋กœ ๋งŒ๋“ค๊ธฐ ์Œ์ด ์•„๋‹Œ ์ •์ˆ˜ N์ด ์ฃผ์–ด์ง„๋‹ค. (0 ≤ N ≤ 10,000,000) www.acmicpc.net ์ฝ”๋“œ #include #include #include using namespace std; string s; map visited; void dfs(int left, int right, string now, set temp){ if(now.length()>=s.length()){ if(now == s) visited[temp] = 1; return; } if(left>0){ temp.insert(s[left-1]+now); dfs(left-1, right, s[left-1]+now, temp); temp.erase(s[left-1]+now); } if(right>s; for.. 2022. 6. 20.
[๋ฐฑ์ค€,c++] 19537๋ฒˆ - ์‹ธ์ด๋ฒ„๊ฐœ๊ฐ•์ดํšŒ ๋ฌธ์ œ 19583๋ฒˆ: ์‹ธ์ด๋ฒ„๊ฐœ๊ฐ•์ดํšŒ ์ฒซ๋ฒˆ์งธ ์ค„์—๋Š” ๊ฐœ๊ฐ•์ดํšŒ๋ฅผ ์‹œ์ž‘ํ•œ ์‹œ๊ฐ„ S, ๊ฐœ๊ฐ•์ดํšŒ๋ฅผ ๋๋‚ธ ์‹œ๊ฐ„ E, ๊ฐœ๊ฐ•์ดํšŒ ์ŠคํŠธ๋ฆฌ๋ฐ์„ ๋๋‚ธ ์‹œ๊ฐ„ Q๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. (00:00 ≤ S < E < Q ≤ 23:59) ๊ฐ ์‹œ๊ฐ„์€ HH:MM์˜ ํ˜•์‹์œผ๋กœ ์ฃผ์–ด์ง„๋‹ค. ๋‘๋ฒˆ์งธ ์ค„๋ถ€ํ„ฐ๋Š” www.acmicpc.net ์ฝ”๋“œ #include #include #include #include #include using namespace std; vector parsing_time(string s){ istringstream ss(s); string stringbuffer; vector v; while(getline(ss,stringbuffer, ':')){ v.push_back(stringbuffer); } return v; } vector.. 2022. 6. 20.
[๋ฐฑ์ค€,c++] 10546๋ฒˆ - ๋ฐฐ๋ถ€๋ฅธ ๋งˆ๋ผํ† ๋„ˆ ๋ฌธ์ œ 10546๋ฒˆ: ๋ฐฐ๋ถ€๋ฅธ ๋งˆ๋ผํ† ๋„ˆ ๋งˆ๋ผํ† ๋„ˆ๋ผ๋ฉด ๊ตญ์ ๊ณผ ๋‚˜์ด๋ฅผ ๋ถˆ๋ฌธํ•˜๊ณ  ๋ˆ„๊ตฌ๋‚˜ ์ฐธ๊ฐ€ํ•˜๊ณ  ์‹ถ์–ดํ•˜๋Š” ๋ฐฑ์ค€ ๋งˆ๋ผํ†ค ๋Œ€ํšŒ๊ฐ€ ์—ด๋ฆฐ๋‹ค. 42.195km๋ฅผ ๋‹ฌ๋ฆฌ๋Š” ์ด ๋งˆ๋ผํ†ค์€ ๋ชจ๋‘๊ฐ€ ์ฐธ๊ฐ€ํ•˜๊ณ  ์‹ถ์–ดํ–ˆ๋˜ ๋งŒํผ ๋งค๋…„ ๋ชจ๋‘๊ฐ€ ์™„์ฃผํ•ด์™”๋‹ค. ๋‹จ, ํ•œ ๋ช… www.acmicpc.net ์ฝ”๋“œ #include #include using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int N; cin>>N; string name; unordered_map umap; for(int i=0; i>name; umap[name]++; } for(int i=0; i>name; umap[name]--; } for(auto it = umap.begin(); it!.. 2022. 6. 19.
[๋ฐฑ์ค€,c++] 5430๋ฒˆ - AC ๋ฌธ์ œ 5430๋ฒˆ: AC ๊ฐ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์— ๋Œ€ํ•ด์„œ, ์ž…๋ ฅ์œผ๋กœ ์ฃผ์–ด์ง„ ์ •์ˆ˜ ๋ฐฐ์—ด์— ํ•จ์ˆ˜๋ฅผ ์ˆ˜ํ–‰ํ•œ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. ๋งŒ์•ฝ, ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•œ ๊ฒฝ์šฐ์—๋Š” error๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. www.acmicpc.net ์ฝ”๋“œ #include #include #include #include #include #include using namespace std; void parsing(string s, deque &dq){ istringstream ss(s); string stringbuffer; while(getline(ss, stringbuffer, ',')){ dq.push_back(stoi(stringbuffer)); } } int main(){ int T; cin>>T; while(T--){ string cmd; cin>>c.. 2022. 6. 19.
[๋ฐฑ์ค€,c++] 18115๋ฒˆ - ์นด๋“œ ๋†“๊ธฐ ๋ฌธ์ œ 18115๋ฒˆ: ์นด๋“œ ๋†“๊ธฐ ์ˆ˜ํ˜„์ด๋Š” ์นด๋“œ ๊ธฐ์ˆ ์„ ์—ฐ์Šตํ•˜๊ณ  ์žˆ๋‹ค. ์ˆ˜ํ˜„์ด์˜ ์†์— ๋“ค๋ฆฐ ์นด๋“œ๋ฅผ ํ•˜๋‚˜์”ฉ ๋‚ด๋ ค๋†“์•„ ๋ฐ”๋‹ฅ์— ์Œ“์œผ๋ ค๊ณ  ํ•œ๋‹ค. ์ˆ˜ํ˜„์ด๊ฐ€ ์“ธ ์ˆ˜ ์žˆ๋Š” ๊ธฐ์ˆ ์€ ๋‹ค์Œ 3๊ฐ€์ง€๋‹ค. ์ œ์ผ ์œ„์˜ ์นด๋“œ 1์žฅ์„ ๋ฐ”๋‹ฅ์— ๋‚ด๋ ค๋†“๋Š”๋‹ค. www.acmicpc.net ์ฝ”๋“œ #include #include #include #include using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int N; cin>>N; vectorv(N); dequedq; for(int i=0; i>v[i]; reverse(v.begin(),v.end()); int num = 1; for(int i:v){ if(i==1) dq.push_back(num); .. 2022. 6. 19.
[๋ฐฑ์ค€,c++] 5397๋ฒˆ - ํ‚ค๋กœ๊ฑฐ ๋ฌธ์ œ 5397๋ฒˆ: ํ‚ค๋กœ๊ฑฐ ์ฒซ์งธ ์ค„์— ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์˜ ๊ฐœ์ˆ˜๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๊ฐ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋Š” ํ•œ์ค„๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๊ณ , ๊ฐ•์‚ฐ์ด๊ฐ€ ์ž…๋ ฅํ•œ ์ˆœ์„œ๋Œ€๋กœ ๊ธธ์ด๊ฐ€ L์ธ ๋ฌธ์ž์—ด์ด ์ฃผ์–ด์ง„๋‹ค. (1 ≤ L ≤ 1,000,000) ๊ฐ•์‚ฐ์ด๊ฐ€ ๋ฐฑ์ŠคํŽ˜์ด์Šค๋ฅผ ์ž… www.acmicpc.net ์ฝ”๋“œ #include #include using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n; cin>>n; while(n--){ listli; auto it = li.begin(); string s; cin>>s; for(char c: s){ if(c=='>'){ if(it!=li.end()) it++; } else if(c==' 2022. 6. 3.
[๋ฐฑ์ค€,c++] 1918๋ฒˆ - ํ›„์œ„ ํ‘œ๊ธฐ์‹ ๋ฌธ์ œ 1918๋ฒˆ: ํ›„์œ„ ํ‘œ๊ธฐ์‹ ์ฒซ์งธ ์ค„์— ์ค‘์œ„ ํ‘œ๊ธฐ์‹์ด ์ฃผ์–ด์ง„๋‹ค. ๋‹จ ์ด ์ˆ˜์‹์˜ ํ”ผ์—ฐ์‚ฐ์ž๋Š” ์•ŒํŒŒ๋ฒณ ๋Œ€๋ฌธ์ž๋กœ ์ด๋ฃจ์–ด์ง€๋ฉฐ ์ˆ˜์‹์—์„œ ํ•œ ๋ฒˆ์”ฉ๋งŒ ๋“ฑ์žฅํ•œ๋‹ค. ๊ทธ๋ฆฌ๊ณ  -A+B์™€ ๊ฐ™์ด -๊ฐ€ ๊ฐ€์žฅ ์•ž์— ์˜ค๊ฑฐ๋‚˜ AB์™€ ๊ฐ™์ด *๊ฐ€ ์ƒ๋žต๋˜๋Š” ๋“ฑ์˜ www.acmicpc.net ์ฝ”๋“œ #include #include using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); string s, ans; cin>>s; stackst; for(char c: s){ if(c=='(') st.push(c); else if(c==')'){ while(st.top()!='('){ cout 2022. 6. 3.
[๋ฐฑ์ค€,c++] 2493๋ฒˆ - ํƒ‘ ๋ฌธ์ œ 2493๋ฒˆ: ํƒ‘ ์ฒซ์งธ ์ค„์— ํƒ‘์˜ ์ˆ˜๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ์ •์ˆ˜ N์ด ์ฃผ์–ด์ง„๋‹ค. N์€ 1 ์ด์ƒ 500,000 ์ดํ•˜์ด๋‹ค. ๋‘˜์งธ ์ค„์—๋Š” N๊ฐœ์˜ ํƒ‘๋“ค์˜ ๋†’์ด๊ฐ€ ์ง์„ ์ƒ์— ๋†“์ธ ์ˆœ์„œ๋Œ€๋กœ ํ•˜๋‚˜์˜ ๋นˆ์นธ์„ ์‚ฌ์ด์— ๋‘๊ณ  ์ฃผ์–ด์ง„๋‹ค. ํƒ‘๋“ค์˜ ๋†’์ด๋Š” 1 www.acmicpc.net ์ฝ”๋“œ #include #include using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int N; cin>>N; stackst; // {ํƒ‘ ๋ฒˆํ˜ธ, ๋†’์ด} for(int i=0; i>height; while(!st.empty()){ if(st.top().second>height){ cout 2022. 6. 3.
[๋ฐฑ์ค€,c++] 2800๋ฒˆ - ๊ด„ํ˜ธ ์ œ๊ฑฐ ๋ฌธ์ œ 2800๋ฒˆ: ๊ด„ํ˜ธ ์ œ๊ฑฐ ์ฒซ์งธ ์ค„์— ์Œ์ด ์•„๋‹Œ ์ •์ˆ˜๋กœ ์ด๋ฃจ์–ด์ง„ ์ˆ˜์‹์ด ์ฃผ์–ด์ง„๋‹ค. ์ด ์ˆ˜์‹์€ ๊ด„ํ˜ธ๊ฐ€ ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ์ณ์ ธ์žˆ๋‹ค. ์ˆซ์ž, '+', '*', '-', '/', '(', ')'๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค. ์ˆ˜์‹์˜ ๊ธธ์ด๋Š” ์ตœ๋Œ€ 200์ด๊ณ , ๊ด„ํ˜ธ ์Œ์€ ์ ์–ด๋„ 1๊ฐœ www.acmicpc.net ์ฝ”๋“œ #include #include #include #include using namespace std; bool except[201]; vectorclose; stack open; set ans; string s; void dfs(int index, int delete_cnt){ if(delete_cnt >= 1){ string temp = ""; for(int i=0; is; for(int i=0; i 2022. 6. 3.