This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define pb push_back | |
#define sz(v) (int)v.size() | |
#define all(v) v.begin(),v.end() | |
#define fastio() ios::sync_with_stdio(0),cin.tie(0) | |
using namespace std; | |
typedef long long ll; | |
const int mod = 1e9 + 7; | |
const int inf = 0x3c3c3c3c; | |
const ll infl = 0x3c3c3c3c3c3c3c3c; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define pb push_back | |
#define sz(v) (int)v.size() | |
#define all(v) v.begin(),v.end() | |
#define fastio() ios::sync_with_stdio(0),cin.tie(0) | |
using namespace std; | |
typedef long long ll; | |
const int mod = 1e9 + 7; | |
const int inf = 0x3c3c3c3c; | |
const ll infl = 0x3c3c3c3c3c3c3c3c; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define REP(i,a,b) for(int i=a;i<=b;++i) | |
#define FOR(i,n) for(int i=0;i<n;++i) | |
#define pb push_back | |
#define all(v) (v).begin(),(v).end() | |
#define sz(v) ((int)(v).size()) | |
#define inp1(a) scanf("%d",&a) | |
#define inp2(a,b) scanf("%d%d",&a,&b) | |
#define inp3(a,b,c) scanf("%d%d%d",&a,&b,&c) | |
#define inp4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define REP(i,a,b) for(int i=a;i<=b;++i) | |
#define FOR(i,n) for(int i=0;i<n;++i) | |
#define pb push_back | |
#define all(v) (v).begin(),(v).end() | |
#define sz(v) ((int)(v).size()) | |
#define inp1(a) scanf("%d",&a) | |
#define inp2(a,b) scanf("%d%d",&a,&b) | |
#define inp3(a,b,c) scanf("%d%d%d",&a,&b,&c) | |
#define inp4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
https://community.topcoder.com/stat?c=problem_statement&pm=11461 | |
dp ๋ฌธ์ ์ด๋ค. ๊ฝค๋ ์ต์ํ ์ ํ์ค ํ๋์ด๋ค. ์ด๋ ํ ์๊ฐ ์์ผ๋ฉด ๋งจ์์๋ฆฌ๋ถํฐ ๋ด๋ ค์ค๋ฉด์ ์กฐ๊ฑด์ ๋ง์กฑํ๋ ๊ฐ๋ฅํ ์ซ์๋ค์ ๊ฒฝ์ฐ์ ์๋ฅผ ๊ตฌํ๋๋ฌธ์ ๋ก | |
๋ณดํต ๋ฌธ์ ์์ ์ฃผ์ด์ง ์ํ์ด๋ ํํ์ ๋ณด๋ฉด์ ํน์ ์๋ฆฌ์๊ฐ ์ํ๋ณด๋ค ๋ฎ์์ง๊ฑฐ๋ ํํ๋ณด๋ค ๋์์ง๋์๊ฐ ๊ทธ ๋ท์๋ฆฌ๋ ํฌ๊ธฐ์๋ํด ์ ํ ์ ๊ฒฝ์ ์ฐ์ง ์์๋ ๋๋ฏ๋ก | |
๊ทธ์ ๋ํ ๋ฉ๋ชจ๋ฅผ bool ํํ๋ก memoization ํด์ฃผ๋ฉด๋๋ค. ์ด ๋ฌธ์ ์์๋ ํํ๊ณผ ์ํ ๋๊ฐ ๋ชจ๋ ์์ผ๋ฏ๋ก ๋๊ฐ๋ฅผ ํจ๊ป ๋ฐ์ ธ์ฃผ๋ฉฐ ๊ณ์ฐ์ ํ๋ฉด๋๊ณ | |
4๋ 7์ ์ ์ธํ ์๊ฐ ์ต๋ ํ๋ฒ๋ง ๋์ฌ ์์๋ค๋ ์กฐ๊ฑด๋ ์์ผ๋ฏ๋ก ์ง๊ธ๊น์ง 4๋ 7์ ์ ์ธํ ์๊ฐ ๋์๋์ง ์๋์๋์ง๋ ํจ๊ป memoization ํด์ฃผ๋ฉด๋๋ค | |
๋จ ์์ง ์์ leading zero๋ง ๋์์๋ 4๋7์ด ์๋์๊ฐ ๋์๋ค๊ณ ์ธ๋ฉด ์๋๊ธฐ ๋๋ฌธ์ ์ด๊ฒ๋ memoization ํด์ค๋ค. ์ฆ boolํํ์ memoization ์ 4๊ฐํด์ฃผ๊ณ | |
ํ์ฌ ๋ช์๋ฆฌ๊น์ง ๋ด์คฌ๋์ง๋ฅผ ํ๋๋ด์ฃผ๋ฉด๋๋๋ฐ 10^16๊น์ง๋๊น ์ต๋ 17์ ๋๋ ๊ฒ์ด๋ค. | |
๊ทธ๋ฆฌ๊ณ ์ง๊ธ๊น์ง๋ ์ด์ง์์ ๋ํด์ ์ด๋ ๊ฒ ์์๋ฆฌ๋ถํฐ ๋ฐ์ ธ์ฃผ๋ฉฐ ์ธ๋๊ฒ์ ๋ง์ด ๋ดค์๋๋ฐ ์ญ์ง์์ ๋ํด์๋ ์ฒ์๋ณธ๊ฒ๊ฐ๋ค. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
https://community.topcoder.com/stat?c=problem_statement&pm=11443 | |
์ฃผ์ด์ง ๋ฌธ์์ด์ ํฐ๋ฆฐ๋๋กฌ์ผ๋ก ๋ง๋๋ dp ๋ฌธ์ ์ด๋ค. | |
๋ถ๋ถ๋ฌธ์ ๋ฅผ ์ ์ํ์๋ฉด | |
dp(i,j) : S[i:j] ๋ฅผ ํฐ๋ฆฐ๋๋กฌ์ผ๋ก ๋ง๋ค๊ธฐ์ํ ์ต์ ๋น์ฉ | |
์ ํ์์ ์๊ฐํด๋ณด๋ฉด ์ ๋์์ ๋ถํฐ ํ๊ธ์ ํน์ ๋๊ธ์์ฉ ๋งค์น์ํค๋ฉด์ ์์ชฝ ๋์ ํ์นธ ์ฉ ์ขํ๋๊ฐ๋ ์์ผ๋ก ๊ตฌ์ฑํ ์๊ฐ ์๋ค. | |
์ด๋ป๊ฒ ์ด๊ฒ ๊ฐ๋ฅํ๋๋ฉด ์ผ์ชฝ๋ ๊ธ์๋ฅผ l, ์ค๋ฅธ์ชฝ๋ ๊ธ์๋ฅผ r ์ด๋ผ๊ณ ํ์๋ l์ r๊ณผ ๋งค์น์ํฌ ์๋์๊ณ ์ค๋ฅธ์ชฝ์ ์ ๊ธ์๋ฅผ ๋ง๋ค์ด์ ๊ทธ๊ฒ๊ณผ | |
๋งค์น์ํฌ ์๋์๊ณ r์ ์ญ์ ํ๊ณ r์ ์ผ์ชฝ ๊ธ์์๋ํด ์ฌ๊ท์ ์ผ๋ก ์ ํํ ์๊ฐ์๋ค. ๊ทธ๋ ๊ธฐ ๋๋ฌธ์ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
https://community.topcoder.com/stat?c=problem_statement&pm=11379 | |
์ด ๋ฌธ์ ๋ N๊ฐ์ ์ํ์ด ์ฃผ์ด์ง๊ณ ๊ทธ ์ํ๋ณด๋ค ์๊ฑฐ๋ ๊ฐ์ ์๋ค์ N๊ฐ ์ ํํ์ฌ ๊ทธ N๊ฐ์ ํฉ๊ณผ OR ์ด ๊ฐ์ ๊ฒฝ์ฐ์ ์๋ฅผ ๊ตฌํ๋ ๋ฌธ์ ์ด๋ค. | |
์กฐ๊ธ๋ง ์๊ฐํด๋ณด๋ฉด ์ํ๋ณด๋ค ์๊ฑฐ๋ ๊ฐ์ N๊ฐ์ ์๋ฅผ 2์ง์๋ก ํํํ์ ๋ ๊ฐ๊ฐ์ ๋นํธ๊ฐ ๊ฒน์น์ง ์๋ ์๋ค์ ์กฐํฉ์ ๊ตฌํ๋ผ๋ ๋ง๊ณผ ๋์น์์ ์ ์ ์๋ค. | |
๊ทธ๋ ๋ค๋ฉด ์ฐ์ ์ํ์ ์ต๋ 10^18 ์ด๋๊น 64๊ฐ์ ๋นํธ๋ฉด ์ถฉ๋ถํ ํํ ๊ฐ๋ฅํ ๊ฒ์ด๋ค. ๊ทธ๋ ๋ค๋ฉด 63๋ฒ์งธ ๋นํธ๋ถํฐ ์ฐจ๋ก๋ก ๋ด๋ ค๊ฐ๋ฉด์ ๊ฐ๊ฐ์ ์ํ์ ๋์ง | |
์๋๋ก ์ด๋ค ์์๊ฒ 1์ ์ค ๊ฒ์ธ์ง๋ฅผ ๊ฒฐ์ ํ๋ฉด ๋๋ค.(๋ฌผ๋ก ์๋ฌด ์์๊ฒ๋ 1์ ์์ค๋๋จ) ์ด๋ค ์์๊ฒ 1์ ์ค ๊ฒ์ธ์ง ๊ฒฐ์ ํ๋ ๋ถ๋ถ์ ๊ทธ๋ฅ | |
์ฌ๊ท ํจ์ ๋ด์์ ๋ฐ๋ณต๋ฌธ์ผ๋ก ๊ตฌํํ๋ฉด ๋๋๋ฐ ๋ฌธ์ ๋ ๊ฐ๊ฐ์ ์๋ง๋ค ์ํ์ ๋๋์ง ๋์ง ์๋์ง๋ฅผ ์ฒดํฌ ํด์ค์ผ ํ๋๋ฐ ์ด๋ค ์์๊ฒ 1์ ์ฃผ๋ฉด ์๊ฐ ๋ณํ๊ธฐ | |
๋๋ฌธ์ ๊ทธ์ ๋ํ ์ ๋ณด๊ฐ ์ธ์๋ก ํ์ํ๋ค. ๊ทธ๋ฐ๋ฐ ๋ชจ๋ ์๋ฅผ ์ธ์๋ก ์ฃผ๊ธฐ์ O(64*10^19) ๊ฐ์ ๊ณต๊ฐ์ด ํ์ํ๋ฏ๋ก ํ๋ค๋ค. | |
์ข๋ง ์๊ฐํด๋ณด๋ฉด ์ํ์ 2์ง์๋ก ํํํ์ ๋ ํน์ ์๋ฆฌ๊ฐ 1์ธ๋ฐ ๊ทธ ์๋ฆฌ์ ์ด ์์๊ฒ 1์ ์ฃผ์ง ์์ผ๋ฉด ๊ทธ ์๋ ์๋ฆฌ์ ์๋ฌด๋ฆฌ 1์ ์ค๋ ์ ๋ ์ํ์ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
https://community.topcoder.com/stat?c=problem_statement&pm=11434 | |
ํ์ด1๊ณผ ๊ฑฐ์ ๋์ผํ๋ฐ ์ฌ๊ทํจ์์ ๊ตฌํ ํํ๊ฐ ์กฐ๊ธ ๋ค๋ฅด๋ค ํ์ด1 ์ด ๋ ๋น ๋ฅผ๊ฒ ๊ฐ์ง๋ง ์ด๋ ๊ฒ๋ ์๊ฐํด ๋ณผ ์ ์์ ๊ฒ ๊ฐ์์ ์จ๋ณธ๋ค. | |
์ฒ์์ ๊ธธ์ด N์ธ ๋ฉ์ด๋ฆฌ๊ฐ ์๋๋ฐ ์ด๊ฑธ ๊ธธ์ด๊ฐ 1์ธ ๋ฉ์ด๋ฆฌ ๊น์ง ๋๋์ด ๊ฐ๋ ๊ณผ์ ์ ์๊ฐํด๋ณด์. ๊ฐ๊ฐ์ ์์ธ์๋ค์ ์ง์๋ค์ ๋ชจ๋ ๋ํ ๊ฐ์ S๋ผ๊ณ ํด๋ณด์ | |
์ด S๊ฐ ์ต๋ํ ๋๋ ์ ์๋ ํ์์ผ ๊ฒ์ด๊ณ , ๊ทธ๋ ๋ค๋ฉด ๋ต์ ์๋ฌด๋ฆฌ ์ปค๋ ์ ๊ฐ๋ณด๋ค ์๊ฑฐ๋ ๊ฐ์ ๊ฒ์ด๋ค. ์๋ํ๋ฉด ๊ธธ์ด๊ฐ 1์ธ ๋ฉ์ด๋ฆฌ๋ก ๋๋ ๋ฒ๋ฆฌ๋ฉด | |
์ฐ๋ฆฌ๊ฐ ๊ฐ์ ธ๊ฐ๊ณ ์ ํ๋ ์นธ์ ๋ฌด์กฐ๊ฑด ๊ฐ์ ธ๊ฐ ์๊ฐ ์๊ธฐ ๋๋ฌธ์ด๋ค. ๊ทธ๋ ๋ค๋ฉด ๋๋๋ ์์์ ๋ํ ๋ชจ๋ ๊ฒฝ์ฐ์ ์๋ฅผ ๋ณด๋ฉด์ ๋งค ์๊ฐ ์๊ฐ ๋ง๋ค ์ค๊ฐ์ | |
๋งจ ์ผ์ชฝ ์นธ๊ณผ์ ์ต์๊ฑฐ๋ฆฌ + ์ง๊ธ๊น์ง ๋๋ ํ์์ ์ต์๊ฐ์ ๊ตฌํ๋ฉด ์ด๊ฒ ๋ต์ด๋ ๊ฒ์ด๋ค. | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
https://community.topcoder.com/stat?c=problem_statement&pm=11434 | |
์ด ๋ฌธ์ ๋ ์ํ์ ์ง์์ด ํ์ํ๋ค. ์ฐ์ ๋ฌธ์ ์์ ์นธ๋ค์ด K๊ฐ๊ฐ ์์ ๋ K์ ์ฝ์์ด๋ฉด์ ์์์ธ ์๋ก ๋๋ ์๊ฐ ์๋ค๊ณ ํ๋๋ฐ | |
์ด๊ฒ์ ๋ฐ๋ก ๋งค ํ์ ์์ธ์๋ก ํ๋ฒ ๋๋ ์ ์๋ค๋ ๊ฒ์ ์๋ฏธํ๋ค. ๊ทธ๋ ๊ธฐ ๋๋ฌธ์ ์์ธ์ ๋ถํด๋ฅผ ํ์ ๋ ์์ธ์๋ค์ ์ง์ ๋ค์ ๋ชจ๋ ๋ํ ๊ฐ์ด | |
์ต๋ํ์ผ๋ก ๋๋ ์ ์๋ ํ์์ธ ๊ฒ ์ด๋ค. ๊ทธ๋ ๋ค๋ฉด ์ฐ๋ฆฌ๊ฐ ํน์ ์นธ์ ๊ฐ์ ธ๊ฐ๊ธฐ ์ํ ์ต์ ํ์๊ฐ ์๋ค๊ณ ์น๋ฉด ๊ทธ ์ต์ ํด๋ | |
๋ช๋ฒ์ ๋๋๊ฒ์ด๊ณ ๋ช๋ฒ์ ์์ผ๋ก ์ด๋์ํฌ ๊ฒ์ด๋ค. ์ฐ์ ๋๋๋ ํ์๋ฅผ ๋จผ์ ๋ณด๋ฉด ๊ฐ๊ฐ์ ์์ธ์ ๋ง๋ค ๋๋๋ ํ์๊ฐ ์์ ๊ฑฐ๊ณ ๊ทธ ํ์๋ 0์ผ ์๋ ์์๊ฒ์ด๋ค. | |
๊ทธ๋ ๋ค๋ฉด ๊ฐ๊ฐ์ ์์ธ์์ ๋ํ์ฌ ๋๋๋ ํ์๋ค์ ๋ชจ๋ ์กฐํฉ์ ๋ํ ๊ฒฝ์ฐ๋ค์ ๋ชจ๋ ๋ณด๋ฉด์ | |
์ฐ๋ฆฌ๊ฐ ๊ณ ๋ฅด๋ ค๊ณ ํ๋ ๋์ด ๋งจ ์ผ์ชฝ ์นธ์ผ๋ก ๋ถํฐ ๋ช ๋งํผ ๋จ์ด์ ธ ์๋์ง ๋ด์ ๊ทธ์ค ์ต์ ๊ฐ์ด ๋ต์ด ๋ ๊ฒ์ด๋ค. | |
๋ฌผ๋ก ๋งจ ์ผ์ชฝ ์นธ์ผ๋ก ๋ถํฐ ๋จ์ด์ง ๊ฑฐ๋ฆฌ๋ min(์ข์ธก์ผ๋ก ๊ฐ์๋ ๊ฑฐ๋ฆฌ, ์ฐ์ธก์ผ๋ก ๊ฐ์๋ ๊ฑฐ๋ฆฌ) ์ผ ๊ฒ์ด๋ค. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
์ฐ์ 1x1x1 ํ๋ธ๋ค๊ณผ LxLxL ํ๋ธ๋ค์ ๋ถํผ์ ์ดํฉ์ ๊ตฌํด๋ณด๋ฉด | |
Ns+Nb*L^3 ์ธ๋ฐ ์ด๊ฒ์ T ๋ผ๊ณ ํด๋ณด์. ๊ทธ๋ผ ์ ์ด๋ ์ฐ๋ฆฌ๊ฐ ์ด ํ๋ธ๋ค์ ํฌ์ฅํ๋ ํ๋์ ํ๋ธ์ ๋ถํผ V๋ T๋ณด๋ค ํฌ๊ฑฐ๋ ๊ฐ๋ค. | |
๊ทธ๋ ๋ค๋ฉด T๋ณด๋ค ํฌ๊ฑฐ๋ ๊ฐ์ ๋ชจ๋ V์ ๋ํด ๊ฒ์ฌํด๋ณด์. ๊ทธ๋ฐ๋ฐ ์ฌ๊ธฐ์ ๋ฐ์ ธ์ค์ผ ํ ๊ฒ์ด ์ธ๊ฐ์ง๊ฐ ์๋ค. | |
์ฒซ๋ฒ์งธ๋ก ํ๋ธ์ ๋ชจ์๋ฆฌ์ ๊ธธ์ด๋ฅผ x,y,z ๋ผ๊ณ ํ ๋ x<=y<=z ๊ด๊ณ๋ฅผ ์ ์งํด์ค์ผ ์ ๋๊ฒ์ ๋ ์์ผ๋ค. ํ์ ํ๋ฉด ๊ฒฐ๊ตญ ๊ฐ์๊ฒ ๋์ค๊ธฐ๋๋ฌธ์ด๋ค. | |
(๊ทธ๋ ๊ธฐ ๋๋ฌธ์ x^3 <= 2e9 ์ผ ๊ฒ์ด๋ค) | |
๋๋ฒ์งธ๋ก ์ง๊ธ ๋ณด๋ V์ ๋ถํผ๊ฐ T๋ณด๋ค ํฌ๋ค ํ ์ง๋ผ๋ Nb๊ฐ์ ํ๋ธ๊ฐ ๋ชจ๋ ๋ค์ด๊ฐ ์ ์๋ ์ํฉ์ด ์๋ค. ์ด๊ฒ์ ๋ถ๋ฆฌ ํด์ฃผ๊ธฐ ์ํด์ | |
LxLxL ํ๋ธ๊ฐ ๋ค์ด๊ฐ ์ ์๋ ๊ฐ์๋ฅผ ์ธ์ด ์ค์ผํ๋๋ฐ ์ด๊ฒ์ (x/L)*(y/L)*(z/L) ์ด๋ค. ์ด๊ฒ์ด Nb๋ณด๋ค ํฌ๊ฑฐ๋ ๊ฐ์์ง๋ฅผ ๋ด์ฃผ๋ฉด๋๋ค. | |
์ธ๋ฒ์งธ๋ก x์ y๊ฐ ์ ํด์ง๋ฉด x*y*z๊ฐ T๋ณด๋ค ํฌ๊ฑฐ๋ ๊ฐ์์ผํ๊ธฐ๋๋ฌธ์ ์ต์ z๊ฐ ์ ํด์งํ ๋ฐ | |
์ด ์ต์z๋ถํฐ ๋ชจ๋ ๊ฐ๋ฅํ z๊ฐ์ ๋ค ๋ด์ฃผ์ง ์์๋ ๋๋ค๋ ๊ฒ์ด๋ค. ๋ฑ ์ด๊ฑฐ ํ๋๋ง ๋ด์ฃผ๋ฉด๋๋ค. ๊ทธ๋ ๊ธฐ ๋๋ฌธ์ ์๊ฐ๋ณต์ก๋๋ |