Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

61 9kyo hwang #214

Merged
merged 12 commits into from
Sep 19, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <iostream>
#include <string>
#include <unordered_set>
#include <unordered_map>

using namespace std;

int main()
{
cin.tie(nullptr)->sync_with_stdio(false);

unordered_set<string> Storage;
unordered_map<string, int> NicknameMap;

int N; cin >> N;
while(N--)
{
string Nickname; cin >> Nickname;
NicknameMap[Nickname]++;

bool bEmplaced = false;
string Prefix{};
for(const char& ch : Nickname)
{
Prefix += ch;
if(Storage.count(Prefix) == 0 && !bEmplaced)
{
cout << Prefix << "\n";
bEmplaced = true;
}
Storage.emplace(Prefix);
}

if(!bEmplaced)
{
string Prefix = Nickname;
if(NicknameMap[Nickname] > 1)
{
Prefix += to_string(NicknameMap[Nickname]);
}
Storage.emplace(Prefix);
cout << Prefix << "\n";
}
}

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include <string>
#include <vector>
#include <unordered_set>

using namespace std;

bool IsUnique(const vector<vector<string>>& Relation, const int RowSize, const int ColSize, int AttributeSet)
{
vector<int> Columns;
for(int Column = 0; Column < ColSize; ++Column)
{
if((AttributeSet >> Column) & 1)
{
Columns.emplace_back(Column);
}
}

unordered_set<string> Set;
for(int Row = 0; Row < RowSize; ++Row)
{
string Attributes{};
for(int Column : Columns)
{
Attributes += Relation[Row][Column];
}
Set.emplace(Attributes);
}

return Set.size() == RowSize;
}

bool IsMinimal(const vector<int>& CandidateKeys, int AttributeSet)
{
for(int CandidateKey : CandidateKeys)
{
if((AttributeSet & CandidateKey) == CandidateKey)
{
return false;
}
}
return true;
}

int solution(vector<vector<string>> Relation)
{
const size_t RowSize = Relation.size(), ColSize = Relation.front().size();
vector<int> CandidateKeys;

for(int AttributeSet = 1; AttributeSet < (1 << ColSize); ++AttributeSet)
{
if(!IsMinimal(CandidateKeys, AttributeSet)) continue;
if(!IsUnique(Relation, RowSize, ColSize, AttributeSet)) continue;

CandidateKeys.emplace_back(AttributeSet);
}

return CandidateKeys.size();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
#include <iostream>
#include <set>

using namespace std;

class Database
{
public:
int Recommend1(int G, int x)
{
if(x == 1)
{
return Recommend1P(G);
}
else if(x == -1)
{
return Recommend1N(G);
}
}

int Recommend2(int x)
{
if(x == 1)
{
return Recommend2P();
}
else if(x == -1)
{
return Recommend2N();
}
}

int Recommend3(int x, int L)
{
if(x == 1)
{
return Recommend3P(L);
}
else if(x == -1)
{
return Recommend3N(L);
}
}

void Add(int P, int L, int G)
{
ProblemByLevel[L].emplace(P);
ProblemByLevelAndGroup[L][G].emplace(P);
Problems[P] = {L, G};
}

void Solved(int P)
{
ProblemByLevel[Problems[P].first].erase(P);
ProblemByLevelAndGroup[Problems[P].first][Problems[P].second].erase(P);
}

private:
set<int> ProblemByLevel[101];
set<int> ProblemByLevelAndGroup[101][101];
pair<int, int> Problems[100001];

int Recommend1P(int G)
{
for(int L = 100; L >= 1; --L)
{
if(!ProblemByLevelAndGroup[L][G].empty())
{
return *(--ProblemByLevelAndGroup[L][G].end());
}
}
}

int Recommend1N(int G)
{
for(int L = 1; L <= 100; ++L)
{
if(!ProblemByLevelAndGroup[L][G].empty())
{
return *ProblemByLevelAndGroup[L][G].begin();
}
}
}

int Recommend2P()
{
for(int L = 100; L >= 1; --L)
{
if(!ProblemByLevel[L].empty())
{
return *(--ProblemByLevel[L].end());
}
}
}

int Recommend2N()
{
for(int L = 1; L <= 100; ++L)
{
if(!ProblemByLevel[L].empty())
{
return *ProblemByLevel[L].begin();
}
}
}

int Recommend3P(int L)
{
for(; L <= 100; ++L)
{
if(!ProblemByLevel[L].empty())
{
return *ProblemByLevel[L].begin();
}
}
return -1;
}

int Recommend3N(int L)
{
for(L -= 1; L >= 1; --L)
{
if(!ProblemByLevel[L].empty())
{
return *(--ProblemByLevel[L].end());
}
}
return -1;
}
};

int main()
{
cin.tie(nullptr)->sync_with_stdio(false);

Database* DB = new Database();

int N; cin >> N;
while(N--)
{
int P, L, G; cin >> P >> L >> G;
DB->Add(P, L, G);
}

int M; cin >> M;
while(M--)
{
string Command; cin >> Command;
if(Command == "recommend") // find Max/Min in Category G
{
int G, x; cin >> G >> x;
cout << DB->Recommend1(G, x) << "\n";
}
else if(Command == "recommend2") // find Max/Min any Category
{
int x; cin >> x;
cout << DB->Recommend2(x) << "\n";
}
else if(Command == "recommend3") // find lower bound
{
int x, L; cin >> x >> L;
cout << DB->Recommend3(x, L) << "\n";
}
else if(Command == "add")
{
int P, L, G; cin >> P >> L >> G;
DB->Add(P, L, G);
}
else if(Command == "solved")
{
int P; cin >> P;
DB->Solved(P);
}
}

delete DB;

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <iostream>
#include <vector>

using namespace std;

enum EDirection {Horizontal, Vertical, Diagonal};
enum EHouse {Empty, Wall};

int main()
{
cin.tie(nullptr)->sync_with_stdio(false);

int N; cin >> N;
vector<vector<int>> House(N + 1, vector(N + 1, 0));
for(int i = 1; i <= N; ++i)
{
for(int j = 1; j <= N; ++j)
{
cin >> House[i][j];
}
}

vector<vector<vector<int>>> DP(N + 1, vector(N + 1, vector(3, 0)));
DP[1][2][EDirection::Horizontal] = 1;

for(int i = 1; i <= N; ++i)
{
for(int j = 3; j <= N; ++j)
{
if(House[i][j] == EHouse::Wall) continue;

DP[i][j][EDirection::Horizontal]
= DP[i][j - 1][EDirection::Horizontal]
+ DP[i][j - 1][EDirection::Diagonal];

DP[i][j][EDirection::Vertical]
= DP[i - 1][j][EDirection::Vertical]
+ DP[i - 1][j][EDirection::Diagonal];

if(House[i - 1][j] == EHouse::Wall || House[i][j - 1] == EHouse::Wall) continue;

DP[i][j][EDirection::Diagonal]
= DP[i - 1][j - 1][Horizontal]
+ DP[i - 1][j - 1][Vertical]
+ DP[i - 1][j - 1][Diagonal];
}
}

cout << DP[N][N][EDirection::Horizontal] + DP[N][N][EDirection::Vertical] + DP[N][N][EDirection::Diagonal];

return 0;
}
Loading
Loading