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

16-InSange #63

Merged
merged 4 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions InSange/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
| 13์ฐจ์‹œ | 2024.05.22 | BFS | [ํŠน์ • ๊ฑฐ๋ฆฌ์˜ ๋„์‹œ ์ฐพ๊ธฐ](https://www.acmicpc.net/problem/18352) | [#13](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/53)]
| 14์ฐจ์‹œ | 2024.05.27 | ํˆฌ ํฌ์ธํ„ฐ | [ํฌ๋„์ฃผ ์‹œ์Œ](https://www.acmicpc.net/problem/31589) | [#14](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/56)]
| 15์ฐจ์‹œ | 2024.05.27 | ์ •๋ ฌ | [ํ†ต๋‚˜๋ฌด ๊ฑด๋„ˆ๋›ฐ๊ธฐ](https://www.acmicpc.net/problem/11497) | [#15](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/57)]
| 16์ฐจ์‹œ | 2024.06.28 | ๊ทธ๋ž˜ํ”„ | [Maximum_Total_Importance_ofRoads](https://leetcode.com/problems/maximum-total-importance-of-roads/) | [#16](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/63)]
=======
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <vector>
#include <queue>

using namespace std;

class Solution {
public:
long long maximumImportance(int n, vector<vector<int>>& roads) {
vector<vector<int>> conn; // road
priority_queue<pair<long long, int>> pq; // connect degree first: degree, second: index
long long answer = 0;

conn.assign(n, vector<int>());

for (auto road : roads)
{
int v1 = road[0];
int v2 = road[1];

conn[v1].push_back(v2);
conn[v2].push_back(v1);
}

for (int i = 0; i < n; i++)
{
pq.push({ conn[i].size(), i });
}

while (!pq.empty())
{
pair<long long, int> cur;
cur = pq.top();
pq.pop();

answer += (n-- * cur.first);
}

return answer;
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include<iostream>
using namespace std;
int dp[1025][1025];
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int size, cnt, start_row, start_col, end_row, end_col,temp;
cin >> size >> cnt;

for (int i = 1; i <=size; i++) {
for (int j = 1; j <=size; j++) {
cin >> temp;
dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + temp;
}
}
for (int k = 0; k < cnt; k++) {
cin >> start_row >> start_col >> end_row >> end_col;
cout << dp[end_row][end_col] - dp[start_row - 1][end_col] - dp[end_row][start_col - 1] + dp[start_row - 1][start_col - 1];
cout << "\n";
}

return 0;
}