arrow_forward همه ارسال‌ها

جزئیات ارسال کد#211

verified
وضعیت داوری نهایی: پذیرفته شد
terminal
زبان برنامه‌نویسی: C++
schedule
ارسال‌کننده و زمان:
Saghar Nojavan (۳ سال پیش)
descriptionsolution.cpp ۳۴ خط • ۵۹۳ بایت
1#include <iostream>
2#include <vector>
3using namespace std;
4
5int main()
6{
7 int n;
8 cin >> n;
9
10 vector<int> houses(2 * n);
11 for (int i = 0; i < 2 * n; i++)
12 {
13 cin >> houses[i];
14 }
15
16 vector<int> house(n + 1, -1);
17 long long totalLength = 0;
18
19 for (int i = 0; i < 2 * n; i++)
20 {
21 int houseNumber = houses[i];
22
23 if (house[houseNumber] != -1)
24 {
25 totalLength += i - house[houseNumber];
26 }
27
28 house[houseNumber] = i;
29 }
30
31 cout << totalLength << endl;
32
33 return 0;
34}
کد ارسال‌شده برای داوری خودکار هاتکدز UTF-8