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

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

verified
وضعیت داوری نهایی: محدودیت زمان تست 13
terminal
زبان برنامه‌نویسی: C++
schedule
ارسال‌کننده و زمان:
shana (۲ سال پیش)
descriptionsolution.cpp ۵۳ خط • ۸۲۸ بایت
1#include <iostream>
2using namespace std;
3int main()
4{
5 int n;
6 cin >> n;
7 int arr[2*n];
8 for ( int i = 0 ; i < 2*n ; i ++ )
9 {
10 cin >> arr[i];
11 }
12
13 int i = 0;
14 int sisi = 1;
15 int metr = 0;
16 int andx = 0;
17 int polo = 0;
18 while ( i < 2*n )
19 {
20 if ( i == (2*n) - 1 )
21 {
22 i = 0;
23 }
24
25 else
26 {
27 i ++;
28 }
29
30 if ( sisi == arr[i] && polo == 0 )
31 {
32 polo ++;
33 andx = i;
34 }
35
36 else if ( sisi == arr[i] && polo == 1 )
37 {
38 polo = 0;
39 sisi ++;
40 metr += abs( i - andx );
41 }
42
43 if ( sisi == n + 1 )
44 {
45 break;
46 }
47 }
48
49 cout << metr;
50
51
52 return 0;
53}
کد ارسال‌شده برای داوری خودکار هاتکدز UTF-8