Skip to content

Conversation

@froglike6
Copy link
Collaborator

@froglike6 froglike6 commented Aug 1, 2025

๐Ÿ”— ๋ฌธ์ œ ๋งํฌ

Silver 3 ์„ธ๊ทธ๋จผํŠธ ํŠธ๋ฆฌ๋ณด๋‹ค๋„ ๋ฐ”๏ฝฅ๋กœ๏ฝฅ๋„ˆ๏ฝฅโ™ก

โœ”๏ธ ์†Œ์š”๋œ ์‹œ๊ฐ„

15๋ถ„

โœจ ์ˆ˜๋„ ์ฝ”๋“œ

์ˆ˜๋„ ์ฝ”๋“œ

์ž…๋ ฅ n

n๋ฒˆ ๋ฐ˜๋ณตํ•˜๋ฉด์„œ:
    ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ด๋ฆ„ name ๊ณผ ๋‚œ์ด๋„ d ๋ฅผ ์ž…๋ ฅ๋ฐ›๊ณ 
    (name, d) ์Œ์„ ๋ฆฌ์ŠคํŠธ algo ์— ์ถ”๊ฐ€ํ•œ๋‹ค

์ž…๋ ฅ m
member โ† ๋นˆ ์‚ฌ์ „

m๋ฒˆ ๋ฐ˜๋ณตํ•˜๋ฉด์„œ:
    ๋ฉค๋ฒ„ ์ด๋ฆ„ name ๊ณผ ํ‹ฐ์–ด tier ๋ฅผ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค
    pref โ† algo ๋ฅผ ( |d โˆ’ tier|,  name ) ๊ธฐ์ค€์œผ๋กœ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌํ•œ๋‹ค
    best1 โ† pref[0] ์˜ name
    best2 โ† pref[1] ์˜ name
    member[name] โ† (best1, best2) ๋กœ ์ €์žฅํ•œ๋‹ค

์ž…๋ ฅ q
cur โ† ์—†์Œ

q๋ฒˆ ๋ฐ˜๋ณตํ•˜๋ฉด์„œ:
    line ์„ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค
    ๋งŒ์•ฝ line ์ด "- chan!" ์œผ๋กœ ๋๋‚œ๋‹ค๋ฉด:
        cur โ† line ์„ " - " ๋กœ ๋‚˜๋ˆˆ ๋’ค ์ฒซ ๋ถ€๋ถ„
        "hai!" ๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค
    ๊ทธ๋ ‡์ง€ ์•Š๋‹ค๋ฉด:
        best1, best2 โ† member[cur]
        "{best2} yori mo {best1}" ํ˜•์‹์œผ๋กœ ์ถœ๋ ฅํ•œ๋‹ค

์—ฌ๋Ÿฌ ๋ฉค๋ฒ„๋“ค์ด ์žˆ์Šต๋‹ˆ๋‹ค. ๊ฐ๊ฐ์˜ ๋ฉค๋ฒ„๋“ค์€ ๋ณธ์ธ์˜ ํ‹ฐ์–ด์™€ ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค. ๋งŒ์•ฝ ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ์—ฌ๋Ÿฌ ๊ฐœ๋ผ๋ฉด, ์‚ฌ์ „ ์ˆœ์œผ๋กœ ์ •๋ ฌํ–ˆ์„ ๋•Œ ๋จผ์ € ์˜ค๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ๋” ์ข‹์•„ํ•ฉ๋‹ˆ๋‹ค.

์ถœ๋ ฅํ•˜๋Š” ํ˜•์‹์€ {๋‘ ๋ฒˆ์งธ๋กœ ์ข‹์•„ํ•˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜} yori mo {์ฒซ ๋ฒˆ์งธ๋กœ ์ข‹์•„ํ•˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜}๊ณผ ๊ฐ™์ด ์ถœ๋ ฅํ•˜๋ฏ€๋กœ, ๊ฐ ๋ฉค๋ฒ„๋‹น 2๊ฐœ์˜ ์•Œ๊ณ ๋ฆฌ์ฆ˜๋งŒ ์ €์žฅํ•˜๋„๋ก ํ–ˆ์Šต๋‹ˆ๋‹ค.

์ €๋Š” ๋”•์…”๋„ˆ๋ฆฌ๋ฅผ ๋งŒ๋“ค์–ด, ๊ฐ๊ฐ์˜ ๋ฉค๋ฒ„์— ๋Œ€ํ•ด ์ข‹์•„ํ•˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์ฐพ๊ณ , ์ฒซ ๋ฒˆ์งธ๋กœ ์ข‹์•„ํ•˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜๊ณผ ๋‘ ๋ฒˆ์งธ๋กœ ์ข‹์•„ํ•˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์ €์žฅํ•˜๋„๋ก ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๊ฐ ์ฟผ๋ฆฌ์— ๋Œ€ํ•ด ์ถœ๋ ฅ ํ˜•์‹์„ ๋งž์ถ”์–ด ์ถœ๋ ฅํ•˜์—ฌ ์ด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

๋‹ค๋ฅธ ์–ธ์–ด๋ฅผ ์‚ฌ์šฉํ–ˆ์„ ๋•Œ๋Š” ์–ด๋–ค ์ž๋ฃŒ๊ตฌ์กฐ๋ฅผ ์‚ฌ์šฉํ• ์ง€ ๊ถ๊ธˆํ•˜๋„ค์š” ใ…Žใ…Ž

๐Ÿ“š ์ƒˆ๋กญ๊ฒŒ ์•Œ๊ฒŒ๋œ ๋‚ด์šฉ

@froglike6 froglike6 self-assigned this Aug 1, 2025
@froglike6 froglike6 requested review from Fnhid and dohyeondol1 August 1, 2025 05:34
@froglike6 froglike6 marked this pull request as ready for review August 1, 2025 05:34
Base automatically changed from 23-froglike6 to 22-froglike6 August 8, 2025 05:04
@froglike6 froglike6 changed the base branch from 22-froglike6 to main August 8, 2025 05:04
Copy link
Contributor

@dohyeondol1 dohyeondol1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋ฌธ์ œ๋ฅผ ์ฝ๊ณ  map, unordered map์œผ๋กœ ํ’€ ์ˆ˜ ์žˆ๋Š” ํ’€์ด๋ฅผ ์ƒ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค.
์ €์žฅํ•ด์•ผ ํ•  ์ •๋ณด๊ฐ€ [์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ข…๋ฅ˜] - [๋‚œ์ด๋„], [๋ฉค๋ฒ„] - [ํ‹ฐ์–ด] ๋กœ ๊ตฌ๋ถ„๋˜๋”๋ผ๊ตฌ์š”.

์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ข…๋ฅ˜๋Š” ๋‚œ์ด๋„ ์ˆœ์œผ๋กœ ์ •๋ ฌ๋  ์ˆ˜ ์žˆ๋„๋ก map์œผ๋กœ,
๋ฉค๋ฒ„๋Š” ์ •๋ ฌ์ด ํ•„์š”ํ•˜์ง€ ์•Š์œผ๋ฏ€๋กœ unordered_map์„ ์‚ฌ์šฉํ•˜์—ฌ ์ €์žฅํ•˜์˜€์Šต๋‹ˆ๋‹ค.

C++
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <unordered_map>
using namespace std;

int N, M, Q;

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    
    cin >> N;
    unordered_map<string, int> diff;
    for(int i = 0; i < N; ++i) {
        string tag;
        int difficulty;
        cin >> tag >> difficulty;
        diff[tag] = difficulty;
    }
    
    cin >> M;
    unordered_map<string, int> tier;
    for(int i = 0; i < M; ++i) {
        string name;
        int t;
        cin >> name >> t;
        tier[name] = t;
    }
    
    cin >> Q;
    string user;
    while(Q--) {
        string cmd1, cmd2, cmd3;
        cin >> cmd1 >> cmd2 >> cmd3;
        
        if(cmd2 == "-") {
            user = cmd1;
            cout << "hai!\n";
        }
        else {
            int currTier = tier[user];
            
            vector<pair<int, string>> distances;
            for(const auto& [tag, difficulty] : diff) {
                distances.push_back({abs(currTier - difficulty), tag});
            }
            
            sort(distances.begin(), distances.end());
            
            cout << distances[1].second << " yori mo " << distances[0].second << '\n';
        }
    }
    
    return 0;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants