amnchouhn's blog

By amnchouhn, history, 4 months ago, In English

I have found a very short solution of 1997C - Even Positions compared to what's available everywhere. Please upvote if found helpful.

Shayan, adedalic, BledDest, Neon, awoo Is there any edge case for this solution?

#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define FAST_IO ios::sync_with_stdio(false); cin.tie(nullptr);

void solve() {
	int n; cin >> n;
	string s; cin >> s;
	int ans = 0;
	for (int i = 0; i < n; i += 2) {
		if (s[i + 1] == ')') {
			ans += 1;
		}
		else {
			ans += 3;
		}
	}
	cout << ans << nl;
}

int main() {
	FAST_IO
	int tc; cin >> tc;
	while (tc--) {solve();}
}

Full text and comments »

  • Vote: I like it
  • +8
  • Vote: I do not like it