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

17-kangrae-jo #61

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

17-kangrae-jo #61

wants to merge 1 commit into from

Conversation

kangrae-jo
Copy link
Collaborator

@kangrae-jo kangrae-jo commented Jan 18, 2025

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

[์ถฉ๋Œ ์œ„ํ—˜ ์ฐพ๊ธฐ]

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

3h ์ด์ƒ...
(๋ฆฌํŒฉํ† ๋ง ํฌํ•จ)

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

PCCP ๊ธฐ์ถœ 3๋ฒˆ ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค (Lv.2)

์ตœ๊ทผ ํ’€์—ˆ๋˜ ๋ฌธ์ œ ์ค‘์— ๊ฐ€์žฅ ํ’€๊ธฐ ํž˜๋“ค์—ˆ๋˜ ๋ฌธ์ œ์ธ ๊ฒƒ ๊ฐ™๋„ค์š”.
๋ฌธ์ œ์œ ํ˜•์€ ์‹œ๋ฎฌ๋ ˆ์ด์…˜์— ๋„ฃ์–ด๋†จ์ง€๋งŒ ๊ตฌํ˜„์˜ ๋Š๋‚Œ์ด ๊ฐ•ํ•ฉ๋‹ˆ๋‹ค.

์ €๋Š” ์ด ๋ฌธ์ œ ์ฝ๊ณ  ์ดํ•ดํ•˜๋Š” ๋ฐ๋งŒ 15๋ถ„์ด ๋„˜๊ฒŒ ๊ฑธ๋ฆฐ ๊ฒƒ ๊ฐ™์•„์š”.
์ƒ๊ฐ๋ณด๋‹ค ๊ณ ๋ คํ•ด์•ผํ•  ์‚ฌํ•ญ์ด ๋งŽ๋”๋ผ๊ตฌ์š”.
๊ทธ๋ž˜์„œ ์ œ๊ฐ€ ๋ช‡์‹œ๊ฐ„ ๋™์•ˆ ์ƒ๊ฐํ•œ ํ’€์ด์˜ ํ๋ฆ„ ์ˆœ์„œ๋Œ€๋กœ ์•Œ๋ ค๋“œ๋ฆด๊ฒŒ์š”.
์ฐธ๊ณ ๋กœ ๋‘๋ฒˆ์งธ ๋ฐฉ์‹๋ถ€ํ„ฐ๋Š” ์ง€ํ”ผํ‹ฐ์™€ ํ•จ๊ป˜ํ–ˆ์Šต๋‹ˆ๋‹ค.


์ฒซ ๋ฒˆ์งธ๋กœ ๋– ์˜ค๋ฅธ ๋ฐฉ์‹

( ์‹คํŒจ, ๋…ผ๋ฆฌ์  ์˜ค๋ฅ˜๊ฐ€ ์žˆ์Œ, 1์‹œ๊ฐ„ ์ด์ƒ ์†Œ์š” )

์ œ์ผ ์ฒ˜์Œ์—๋Š” 2์ฐจ์› ๋ฐฐ์—ด์„ ๋งŒ๋“ค์–ด์„œ ๋กœ๋ด‡์„ ํ•˜๋‚˜์”ฉ ํฌ์ธํŠธ๋กœ ์›€์ง์ด๊ณ , ์›€์ง์ธ ๋กœ๋ด‡์ด ๋‹ค๋…€๊ฐ„ ์ž๋ฆฌ๋Š” 1, 2, 3, .. ์ด๋ ‡๊ฒŒ ํ”์ ์„ ๋‚จ๊ธฐ๊ณ  ๊ฐ€๋Š” ์ฝ”๋“œ๋ฅผ ์™„์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค.
์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ๊ฐ™์€ ์ˆซ์ž์˜ ํ”์ ์„ ๋‚จ๊ธด ๋กœ๋ด‡์€ ๊ฐ™์€ ์‹œ๊ฐ„์— ๊ฒน์ณค๋‹ค๋Š” ์˜๋ฏธ๊ฐ€ ๋˜๊ฒ ์ฃ ?
์ด๋•Œ ์นด์šดํŠธ๋ฅผ +1 ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

๊ทธ๋Ÿฐ๋ฐ ์ด ๋ฐฉ์‹์€ ์ž˜๋ชป๋œ ๋ฐฉ์‹์˜ ํ’€์ด์ž…๋‹ˆ๋‹ค.
๋ฐ˜๋ก€๋ฅผ ๋“ค์–ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ์˜ˆ์‹œ 3๋ฒˆ์˜ ์ผ€์ด์Šค ์ฒ˜๋Ÿผ ๋กœ๋ด‡์ด ์›€์ง์ผ ๋•Œ, ์ด์ „์— ์›€์ง์ธ ๋กœ๋ด‡์˜ ํ”์ ์„ ํ˜„์žฌ ์›€์ง์ด๋Š” ๋กœ๋ด‡์ด ์ž์‹ ์˜ ํ”์ ์œผ๋กœ ๋ฎ์–ด ์“ฐ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค!
์ด ์˜ค๋ฅ˜๋ฅผ ์ƒ๊ฐํ•˜๋Š”๋ฐ ์—„์ฒญ ์‹œ๊ฐ„์ด ๋“ค์—ˆ๋„ค์š”...

๋‘ ๋ฒˆ์งธ๋กœ ๋– ์˜ค๋ฅธ ๋ฐฉ์‹

( ์‹คํŒจ, ๊ตฌํ˜„์˜ ์–ด๋ ค์›€ 1์‹œ๊ฐ„ ์ด์ƒ ์†Œ์š” )

๊ทธ๋ž˜์„œ ๋– ์˜ค๋ฅธ ๋ฐฉ๋ฒ•์€ ๋กœ๋ด‡์˜ ์›€์ง์ž„(ํ”์ )์„ ๊ธฐ๋กํ•˜๋Š” 2์ฐจ์› ๋ฐฐ์—ด์„ ๋งŒ๋“ค์ง€ ๋ง์ž ์ž…๋‹ˆ๋‹ค.
๋Œ€์‹ , ์ถฉ๋Œ ๋น„๊ต ์‹œ ์‚ฌ์šฉ๋˜๋Š” x ์ขŒํ‘œ, y ์ขŒํ‘œ, time ์œผ๋กœ ๊ตฌ๋ถ„๋˜๋Š” ๋ฐฐ์—ด์„ ๋งŒ๋“ค์–ด์•ผ ๊ฒ ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค.
๋ฐ”๋กœ ๋– ์˜ค๋ฅธ ๊ฒƒ์€ ๊ตฌ์กฐ์ฒด๋ฅผ ํ™œ์šฉํ•˜์—ฌ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ํ™œ์šฉํ•˜๋Š” ๊ฒƒ์ด์—ˆ์Šต๋‹ˆ๋‹ค.

struct Point {
    int x, y, time;
};

map<Point, int> history

๊ทธ๋Ÿฐ๋ฐ ๋ฌธ์ œ๋Š” ์‚ฌ์šฉ์ž๊ฐ€ ์ •์˜ํ•œ ๊ตฌ์กฐ์ฒด๋ฅผ key๋กœ ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ == operation์„ ์ •์˜ํ•ด์ค˜์•ผํ•˜๊ณ , ํ•ด์‰ฌ ํ•จ์ˆ˜๋„ ์ •์˜ํ•ด์•ผํ•œ๋‹ค๋Š” ์ ์ž…๋‹ˆ๋‹ค...
์ด๊ฑด ์•„๋‹ˆ๋‹ค ์‹ถ์–ด์„œ ๋‹ค์Œ ๋ฐฉ๋ฒ•์œผ๋กœ ๋„˜์–ด๊ฐ‘๋‹ˆ๋‹ค.

์„ธ ๋ฒˆ์งธ๋กœ ๋– ์˜ค๋ฅธ ๋ฐฉ์‹

( ์„ฑ๊ณต, ์ปจํ…Œ์ด๋„ˆ์˜ ์˜๋ฏธ๋งŒ ์ดํ•ดํ•˜๋ฉด ์‰ฌ์›€ )

๊ทธ ๋’ค์— ๋– ์˜ค๋ฅธ ๋ฐฉ์‹์€ time์„ ์ธ๋ฑ์Šค๋กœ ๊ฐ€์ง€๋Š” ์ปจํ…Œ์ด๋„ˆ์— x์ขŒํ‘œ, y์ขŒํ‘œ๋ฅผ ๋„ฃ๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.
์ด๋ฅผ ๊ตฌํ˜„ํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค!

// ๊ฐ ์‹œ์ ์—์„œ ๋กœ๋ด‡๋“ค์˜ ์œ„์น˜๋ฅผ ๊ธฐ๋กํ•  ๋งต (์‹œ๊ฐ„, ์ขŒํ‘œ) -> ๋กœ๋ด‡ ์ˆ˜
vector<map<pair<int, int>, int>> history(100005);

์ด๊ฑฐ๋ฅผ ์ œ๊ฐ€ ๋‹ค์‹œ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์„์ง€ ๋ชจ๋ฅด๊ฒ ๋„ค์š”...
(์ดํ•ดํ•˜๊ธฐ ์–ด๋ ต๋‹ค๋ฉด ์‹œ๊ฐ„๊ณผ ์ขŒํ‘œ๋ฅผ ์‚ฌ์šฉํ•œ 2์ฐจ์› ๋ฐฐ์—ด... ์ฒ˜๋Ÿผ ์ƒ๊ฐํ•ด๋„ ๋  ๋“ฏ ํ•ฉ๋‹ˆ๋‹ค?)

์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ๊ฐ™์€ ์‹œ๊ฐ„๋งˆ๋‹ค ๋กœ๋ด‡์˜ ์œ„์น˜๋ฅผ ์•Œ ์ˆ˜ ์žˆ๊ณ , ๊ทธ ์ค‘ ๊ฐ™์€ x์ขŒํ‘œ, y์ขŒํ‘œ๋ฅผ ๊ฐ€์ง„ ๋กœ๋ด‡์€ ์ถฉ๋Œ์œ„ํ—˜์ด ์žˆ๋Š” ๊ฒƒ์ด ๋˜์ฃ !
์ฐธ๊ณ ๋กœ history์˜ ํฌ๊ธฐ๋Š” 100005๋กœ ์ž„์˜์˜ ์ตœ๋Œ€๊ฐ’์œผ๋กœ ์„ค์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.
์ตœ๋Œ€๊ฐ’์ด๋ผ๋Š” ๊ทผ๊ฑฐ๋Š” r๊ณผ c์˜ ์ตœ๋Œ€๊ฐ’์€ 100์ด๊ณ , ์ตœ๋Œ€ ์ด๋™ ๊ฑฐ๋ฆฌ๋Š”100 * 100 ์ด๋‹ˆ๊นŒ ์ตœ๋Œ€ ์ด๋™ ์‹œ๊ฐ„๋„ ํ•œ 100000์ด๊ฒ ์ฃ ?

๋‚˜๋จธ์ง€ ๊ตฌํ˜„ ์ฝ”๋“œ๋Š” ์ž˜ ์ฝ์–ด๋ณด๋ฉด ์ดํ•ด๋ ๊ฑฐ์—์š”.
์ถ”๊ฐ€๋กœ ์ฃผ์˜ํ•  ์ ์ด ์žˆ๊ธดํ•ฉ๋‹ˆ๋‹ค.

  1. ๋กœ๋ด‡์€ ์—ฌ๋Ÿฌ๊ฐœ์˜ ํฌ์ธํŠธ๋ฅผ ๋‹ค๋…€๊ฐˆ ์ˆ˜ ์žˆ๋‹ค๋Š” ์ 
  2. ์‹œ์ž‘ ์ง€์ ๋„ ์ฒดํฌ ํ•ด์•ผํ•œ๋‹ค๋Š” ์ 
  3. y์ขŒํ‘œ ๋จผ์ € ์ด๋™ ํ•ด์•ผํ•œ๋‹ค๋Š” ์ 

์ด ์ •๋„๊ฐ€ ์žˆ๊ฒ ๋„ค์š”

์ฐธ๊ณ ๋กœ ๋‹ค๋ฅธ ์‚ฌ๋žŒ์˜ ํ’€์ด ๋“ฑ ๋‹ค๋ฅธ ์ •๋‹ต์ง€ ๋ณด๋‹ค ์ œ ํ’€์ด๊ฐ€ ์ œ์ผ ์‰ฝ์Šต๋‹ˆ๋‹ค. ( ์•„๋งˆ๋„์š”.. )
์ œ๊ฐ€ ๋ช‡ ์‹œ๊ฐ„ ๋™์•ˆ ํ•œ ๊ณ ๋ฏผ์ด ๋‹ค ๋‹ด๊ฒผ๋Š”์ง€ ๋ชจ๋ฅด๊ฒ ๋„ค์š”...
์งˆ๋ฌธ๋„ ๋งŽ์ด ํ•ด์ฃผ์„ธ์š”

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

์—ฌ๋Ÿฌ ์›์†Œ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋™์ผ์„ฑ ๋น„๊ต๋ฅผ ํ•˜๊ณ  ์‹ถ์„ ๋•Œ๋Š” ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ž˜ ํ™œ์šฉํ•˜์ž!

Copy link
Collaborator

@g0rnn g0rnn left a comment

Choose a reason for hiding this comment

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

์ •๋ง ๋„ˆ๋ฌด๋‚˜ ์–ด๋ ค์šด ๋ฌธ์ œ๋„ค์š”.. ์ด๊ฒŒ ๋ ˆ๋ฒจ 3์ด๋ผ๋Š”๊ฒŒ ๋ฏฟ๊ธฐ์ง€๊ฐ€ ์•Š์„ ์ •๋„๋กœ..

์ €๋Š” 4์‹œ๊ฐ„์€ ๋„˜๊ฒŒ ๊ฑธ๋ฆฐ๊ฒƒ ๊ฐ™์•„์š”. 3์‹œ๊ฐ„ ์ •๋„ ํ’€๋‹ค๊ฐ€ ์„ค๊ณ„๊ฐ€ ์ž˜๋ชป๋˜์—ˆ๋‹ค๋Š” ๊ฑธ ๊นจ๋‹ซ๊ณ  ๊ฐ•๋ž˜๋‹˜ ์ฝ”๋“œ๋ณด๊ณ  ์ €์˜ ์ž˜๋ชป๋œ ์„ค๊ณ„๋ฅผ ๋ˆˆ์น˜์ฑˆ ํ›„ ๋‹ค์‹œ ์„ค๊ณ„๋ถ€ํ„ฐ ์‹œ์ž‘ํ–ˆ์Šต๋‹ˆ๋‹ค.

๊ทธ๋Ÿฌ๋‹ค ๋ณด๋‹ˆ ๊ฐ•๋ž˜๋‹˜ ์ฝ”๋“œ์™€ ๋น„์Šทํ•˜๊ฒŒ ์ขŒํ‘œ๋ฅผ key๋กœ ํ•˜๊ณ  ์ถฉ๋Œ๋˜๋Š” ๋กœ๋ด‡์„ value๋กœ ํ•˜๋Š” map์„ ์‚ฌ์šฉํ•˜์˜€๊ณ  ์ž์—ฐ์Šค๋ ˆ time์ด๋ผ๋Š” ์ˆซ์ž ๊ฐ’์€ index๋กœ ๊ตฌํ˜„ํ–ˆ์Šต๋‹ˆ๋‹ค.

์™„์„ฑํ•˜๊ณ  ๋‚˜๋‹ˆ ์ œ ์ฝ”๋“œ๊ฐ€ ๊ฐ€์žฅ ์‰ฌ์›Œ๋ณด์˜€๋Š”๋ฐ ๊ฐ•๋ž˜๋‹˜์˜ ์ฝ”๋“œ๋ฅผ ๋ณด๊ณ  ๋‚œ ํ›„ ๋ถˆํ•„์š”ํ•œ ๊ตฌ์กฐ์ฒด๋กœ ์ธํ•ด ๋” ๋ณต์žกํ•ด์ง„ ๊ฒƒ ๊ฐ™์•„ ์•„์‰ฝ๋„ค์š”. ์‹ค์ œ ์ฝ”๋“œ๋ฅผ ๋ณด๋ฉด ๊ตฌ์กฐ์ฒด๊ฐ€ ํ•„์š”์—†์–ด๋„ ๋ ๋“ฏ ํ•ฉ๋‹ˆ๋‹ค. (์‚ฌ์‹ค set์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ ๊ตฌ์กฐ์ฒด์™€ ์—ฐ์‚ฐ์ž ์˜ค๋ฒ„๋กœ๋”ฉ์„ ์‚ฌ์šฉํ•˜์˜€๋Š”๋ฐ ์˜๋ฏธ๊ฐ€ ์—†์–ด์กŒ๋‹ค๋Š”๊ฑธ ์žŠ์–ด๋ฒ„๋ ธ์—ˆ๋„ค์š”.)

code
#include <string>
#include <vector>
#include <map>

using namespace std;

struct Coord {
    int r, c;
    Coord(vector<int> point) : r(point[0] - 1), c(point[1] - 1) {}

    bool operator==(const Coord &other) const {return r==other.r && c==other.c;}
    bool operator!=(const Coord &other) const { return !(*this == other); }
    bool operator<(const Coord &other) const {
        return (r < other.r) || (r == other.r && c < other.c);
    }

    string str() const { return "(" + to_string(r) + "," + to_string(c) + ")"; }
};

void move(Coord &start, Coord &end) {
    if (start.r < end.r) start.r++;
    else if (start.r > end.r) start.r--;
    else if (start.c < end.c) start.c++;
    else if (start.c > end.c) start.c--;
}

int solution(vector<vector<int> > points, vector<vector<int> > routes) {
    vector<map<string, int> > report(20000);
    for (auto &route: routes) {
        int time = 0;
        for (int i = 1; i < route.size(); i++) {
            int s = route[i - 1]; //์ถœ๋ฐœ์ง€
            int e = route[i]; //๋ชฉ์ ์ง€
            Coord start = Coord(points[s - 1]);
            Coord end = Coord(points[e - 1]);

            if (time == 0) report[time++][start.str()]++; //์ถœ๋ฐœ์ง€๋ฅผ ๊ธฐ๋ก
            while (start != end) {
                //move
                move(start, end);
                //write
                report[time][start.str()]++;
                time++;
            }
        }
    }
    int danger = 0;
    for (int time = 0; time < 20000; time++) {
        if (report[time].empty()) break;
        for (auto &[coord, dup]: report[time])
            if (dup >= 2) danger++;
    }
    return danger;
}

Comment on lines +28 to +29
if (y1 != y2) y1 += (y2 > y1 ? 1 : -1);
else x1 += (x2 > x1 ? 1 : -1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

๋กœ๋ด‡์ด ์•„์ฃผ ์˜ˆ์ˆ ์ ์œผ๋กœ ์›€์ง์ด๋Š” ๊ตฐ์š”. ์ •๋ง ๊ฐ„๋‹จํ•˜๊ฒŒ ์ž˜ ๊ตฌํ˜„ํ•˜์…จ๋„ค์š” ๐Ÿ‘

int answer = 0;

// ๊ฐ ์‹œ์ ์—์„œ ๋กœ๋ด‡๋“ค์˜ ์œ„์น˜๋ฅผ ๊ธฐ๋กํ•  ๋งต (์‹œ๊ฐ„, ์ขŒํ‘œ) -> ๋กœ๋ด‡ ์ˆ˜
vector<map<pair<int, int>, int>> history(100005);
Copy link
Collaborator

Choose a reason for hiding this comment

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

์ €๋Š” ์‹œ๊ฐ„์˜ ์ตœ๋Œ€๋Š” 20000์œผ๋กœ ์žก์•˜์Šต๋‹ˆ๋‹ค. ๋กœ๋ด‡์ด ๋Œ์•„๋‹ค๋‹ˆ๋Š” ์ง€๋„์˜ size๋Š” ์ตœ๋Œ€ 100x100 ์ด์–ด์„œ ์ตœ๋Œ€ ๊ฑฐ๋ฆฌ๋Š” 200์ด๋ผ ์ƒ๊ฐํ–ˆ๊ณ  ์ด๊ฒƒ์ด ๋ฌธ์ œ์˜ ์กฐ๊ฑด์— ์˜ํ•ด ์ตœ๋Œ€ 100๋ฒˆ ๋ฐ˜๋ณต๋  ์ˆ˜ ์žˆ์–ด์„œ 20000์œผ๋กœ ํ–ˆ์Šต๋‹ˆ๋‹ค.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

๋ถˆํ•„์š”ํ•œ ๊ตฌ์กฐ์ฒด๋กœ ์ธํ•ด ๋” ๋ณต์žกํ•ด์ง„ ๊ฒƒ ๊ฐ™์•„ ์•„์‰ฝ๋„ค์š”.

๋งž์•„์š” ์ €๋„ ๋‘๋ฒˆ์งธ ์‹œ๋„๋กœ ๊ตฌ์กฐ์ฒด๊ฐ€ ๋– ์˜ฌ๋ž๋Š”๋ฐ ๋น„๊ต ์—ฐ์‚ฐ ์ •์˜ํ•˜๋Š”๊ฒŒ ๊ฝค ํฐ์ž‘์—…์ด๋ผ ์ƒ๊ฐํ•ด์„œ ํฌ๊ธฐํ–ˆ์Šต๋‹ˆ๋‹ค...


์ €๋Š” ์‹œ๊ฐ„์˜ ์ตœ๋Œ€๋Š” 20000์œผ๋กœ ์žก์•˜์Šต๋‹ˆ๋‹ค. ๋กœ๋ด‡์ด ๋Œ์•„๋‹ค๋‹ˆ๋Š” ์ง€๋„์˜ size๋Š” ์ตœ๋Œ€ 100x100 ์ด์–ด์„œ ์ตœ๋Œ€ ๊ฑฐ๋ฆฌ๋Š” 200์ด๋ผ ์ƒ๊ฐํ–ˆ๊ณ  ์ด๊ฒƒ์ด ๋ฌธ์ œ์˜ ์กฐ๊ฑด์— ์˜ํ•ด ์ตœ๋Œ€ 100๋ฒˆ ๋ฐ˜๋ณต๋  ์ˆ˜ ์žˆ์–ด์„œ 20000์œผ๋กœ ํ–ˆ์Šต๋‹ˆ๋‹ค.

์•— ๊ทธ๋Ÿฐ๊ฐ€์š”? ๋ณด๋“œ์˜ ๋ชจ๋“  ์นธ์„ ๊ฒฝ์œ ํ•œ๋‹ค๊ณ  ํ–ˆ์„๋•Œ 10_000 ์ฏค ์ด๋ผ๊ณ  ์ƒ๊ฐํ–ˆ๋Š”๋ฐ .....
์ด์ œ๋ณด๋‹ˆ๊นŒ 100_005 ๋ผ๊ณ  10๋ฐฐ๋‚˜ ํฌ๊ฒŒ ์žก์•„๋ฒ„๋ ธ์—ˆ๋„ค์š” ใ…‹ใ…‹ใ…‹ใ…‹

Comment on lines +17 to +18
history[time][{y1, x1}]++;
time++;
Copy link
Collaborator

Choose a reason for hiding this comment

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

time์„ ์ธ๋ฑ์Šค๋กœ ์ขŒํ‘œ๋ฅผ ์ €์žฅํ•˜๋Š” ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๋– ์˜ฌ๋ฆด ์ˆ˜ ์žˆ๋‹ค๋‹ˆ
๋Œ€๋‹จํ•ฉ๋‹ˆ๋‹ค..
์ €๋„ ๋ฌธ์ œ ์ดํ•ด์—๋งŒ ์˜ค๋žœ ์‹œ๊ฐ„์ด ๊ฑธ๋ ธ๊ณ 
๊ตฌํ˜„๋„ ๊ฒฐ๊ตญ ์ง€์„ ์ƒ ์ฐธ๊ณ ๋งŒ ํ•ด์„œ ์ œ ์ฝ”๋“œ๊ฐ€ ์•„๋‹ˆ๋„ค์š”...

๋‹ค๋งŒ ์ฐธ๊ณ ํ•˜๋ฉด์„œ ๋ฐฐ์šด ์ ์€
์ž๋ฐ”์—์„œ๋Š” Map์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ ์ขŒํ‘œ์— ์ˆœ์„œ๋ฅผ ๋ฉ”๊ธธ ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

Map<Integer, int[]> pointMap = new HashMap<>();
 for (int i = 0; i < points.length; i++) {
            pointMap.put(i + 1, points[i]);
 }

์ด๋Ÿฐ ์‹์œผ๋กœ ์—ฌ๊ธฐ์— points = [[3,2], [6,4]]๋ฅผ ์ž…๋ ฅํ•˜๋ฉด
pointMap = {1 -> [3,2], 2 -> [6,4]}๊ฐ€ ์ €์žฅ๋ฉ๋‹ˆ๋‹ค.

๋‹ค์Œ ๊ธฐํšŒ์— ํ•ด๋‹น ๋ฌธ์ œ ๋‹ค์‹œ ํ’€์–ด๋ณด๊ณ  ์‹ฌ๊ธฐ์ผ์ „ํ•˜์—ฌ PCCP ์žฌ๋„์ „ ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.
์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค!

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