File tree 5 files changed +179
-0
lines changed
5 files changed +179
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+ #define REP (i,a,b ) for (int i=(a);i<(b);++i)
3
+ #define rep (i,n ) REP(i,0 ,n)
4
+ using namespace std ;
5
+
6
+ int main () {
7
+ int n;
8
+ cin >> n;
9
+ rep (i, n) {
10
+ int a;
11
+ cin >> a;
12
+ a -= (a % 2 == 0 ? 1 : 0 );
13
+ if (i == n - 1 )
14
+ cout << a << endl;
15
+ else
16
+ cout << a << " " ;
17
+ }
18
+ return 0 ;
19
+ }
20
+
Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+ #define REP (i,a,b ) for (int i=(a);i<(b);++i)
3
+ #define rep (i,n ) REP(i,0 ,n)
4
+ using namespace std ;
5
+
6
+ const int MAX_A = 2000 ;
7
+
8
+ int main () {
9
+ int n, k;
10
+ cin >> n >> k;
11
+ int a[n], tmp[n], v[MAX_A] = {};
12
+ rep (i, n) {
13
+ cin >> a[i];
14
+ tmp[i] = a[i];
15
+ }
16
+ sort (tmp, tmp+n);
17
+ int sum = 0 ;
18
+ REP (i, n - k, n) {
19
+ sum += tmp[i];
20
+ v[tmp[i]] += 1 ;
21
+ }
22
+ cout << sum << endl;
23
+ sum = 0 ;
24
+ rep (i, n) {
25
+ sum++;
26
+ if (v[a[i]] && k > 1 ) {
27
+ v[a[i]]--;
28
+ k--;
29
+ cout << sum << " " ;
30
+ sum = 0 ;
31
+ }
32
+ }
33
+ cout << sum << endl;
34
+ return 0 ;
35
+ }
36
+
Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+ #define REP (i,a,b ) for (int i=(a);i<(b);++i)
3
+ #define rep (i,n ) REP(i,0 ,n)
4
+ using namespace std ;
5
+ using ll = long long ;
6
+
7
+ const int MAX_A = 2000 ;
8
+
9
+ int main () {
10
+ ll n;
11
+ cin >> n;
12
+ ll a[n];
13
+ rep (i, n) cin >> a[i];
14
+ ll idx1 = 0 , idx3 = n - 1 ;
15
+ ll sum1 = 0 , sum3 = 0 ;
16
+ ll ans = 0 ;
17
+ while (true ) {
18
+ if (idx1 >= idx3)
19
+ break ;
20
+ sum1 += a[idx1++];
21
+ // cout << "sum1, idx: " << sum1 << ", " << idx1 << endl;
22
+ // cout << "sum3, idx: " << sum3 << ", " << idx3 << endl;
23
+ while (idx1 <= idx3 && sum3 + a[idx3] <= sum1)
24
+ sum3 += a[idx3--];
25
+ if (sum1 == sum3)
26
+ ans = sum1;
27
+ }
28
+ cout << ans << endl;
29
+ return 0 ;
30
+ }
31
+
Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+ #define REP (i,a,b ) for (int i=(a);i<(int )(b);++i)
3
+ #define rep (i,n ) REP(i,0 ,n)
4
+ using namespace std ;
5
+
6
+ int main () {
7
+ int n;
8
+ string a, b;
9
+ cin >> n >> a >> b;
10
+ int ans = 0 ;
11
+ rep (i, (n + 1 ) / 2 ) {
12
+ if (n % 2 == 1 && i == n / 2 ) {
13
+ if (a[i] != b[i]) ans += 1 ;
14
+ continue ;
15
+ }
16
+ if (a[i] == b[i] && a[n - i - 1 ] == b[n - i - 1 ]) continue ;
17
+ if (a[i] == a[n - i - 1 ] && b[i] == b[n - i - 1 ]) continue ;
18
+ if (a[i] == b[n - i - 1 ] && b[i] == a[n - i - 1 ]) continue ;
19
+
20
+ set<char > s;
21
+ s.insert (a[i]); s.insert (a[n - i - 1 ]);
22
+ s.insert (b[i]); s.insert (b[n - i - 1 ]);
23
+ if (s.size () > 2 ) {
24
+ if (a[i] == b[i] || a[n - i - 1 ] == b[n - i - 1 ])
25
+ ans += 1 ;
26
+ else if (a[i] == b[n - i - 1 ] || b[i] == a[n - i - 1 ])
27
+ ans += 1 ;
28
+ else if (b[i] == b[n - i - 1 ])
29
+ ans += 1 ;
30
+ else
31
+ ans += 2 ;
32
+ }
33
+ else
34
+ ans += 1 ;
35
+ }
36
+ cout << ans << endl;
37
+ }
38
+
Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+ #define REP (i,a,b ) for (int i=(a);i<(int )(b);++i)
3
+ #define rep (i,n ) REP(i,0 ,n)
4
+ using namespace std ;
5
+
6
+ const int MAX_N = 200000 ;
7
+
8
+ int dfs (int id);
9
+
10
+ struct vertex {
11
+ vector<vertex*> edge;
12
+ int id, t, n;
13
+ };
14
+ vertex G[MAX_N + 1 ];
15
+ int a[MAX_N + 1 ];
16
+ int idx;
17
+
18
+ int main () {
19
+ int n, q;
20
+ cin >> n >> q;
21
+ G[1 ].id = 1 ;
22
+ for (int i = 2 ; i <= n; ++i) {
23
+ int p;
24
+ cin >> p;
25
+ G[i].id = i;
26
+ G[p].edge .push_back (&G[i]);
27
+ }
28
+ idx = 1 ;
29
+ dfs (1 );
30
+ // rep(i, n + 1) cout << a[i] << ", " << G[a[i]].t << endl;
31
+ rep (i, q) {
32
+ int u, k;
33
+ cin >> u >> k;
34
+ if (k > G[u].t ) {
35
+ cout << -1 << endl;
36
+ continue ;
37
+ }
38
+ cout << a[G[u].n + k - 1 ] << endl;
39
+ }
40
+ }
41
+
42
+ int dfs (int id) {
43
+ int length = G[id].edge .size ();
44
+ G[id].n = idx;
45
+ a[idx++] = id;
46
+ if (length == 0 )
47
+ return G[id].t = 1 ;
48
+
49
+ int sum = 1 ;
50
+ rep (i, length)
51
+ sum += dfs (G[id].edge [i]->id );
52
+ G[id].t = sum;
53
+ return sum;
54
+ }
You can’t perform that action at this time.
0 commit comments