Submission #17236475
Source Code Expand
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <cassert>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include "atcoder/all"
using namespace atcoder;
using namespace std;
typedef long long ll;
#define pb push_back
#define rep(i, n) for(int i=0;i<(n);i++)
#define P pair<int,int>
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
namespace ori{
template <typename T>
void erase(std::vector<T> &v)
{
std::sort(v.begin(),v.end());
v.erase(std::unique(v.begin(),v.end()),v.end());
return;
}
template<typename T>
int find_index(std::vector<T> v, T find, string key)
{
std::sort(v.begin(),v.end());
if(key=="left")
{
return (std::distance(v.begin(),lower_bound(v.begin(),v.end(),find)));
}
if(key=="right")
{
return (std::distance(v.begin(),upper_bound(v.begin(),v.end(),find))-1);
}
else
{
return -1;
}
}
}
vector<string> split(const string &s, char delim) {
vector<string> elems;
stringstream ss(s);
string item;
while (getline(ss, item, delim)) {
if (!item.empty()) {
elems.push_back(item);
}
}
return elems;
}
const int x8[] = {0, 0, 1, -1, -1, 1, -1, 1};
const int y8[] = {-1, 1, 0, 0, -1, -1, 1, 1};
const int x4[] = {1, -1, 0, 0};
const int y4[] = {0, 0, -1, 1};
const int MOD = 1'000'000'007;
bool ok(char a, char b){
if((a == 'A' && b == 'T') ||(a == 'T' && b == 'A') || (a == 'G' && b == 'C') ||(a == 'C' && b == 'G'))
{
return true;
}
else
return false;
}
void task()
{
int n; string s; ll ans = 0;
cin >> n >> s;
vector<int> a(n+1),g(n+1),c(n+1),t(n+1);
rep(i,n){
if(s[i] == 'A') a[i+1]++;
if(s[i] == 'G') g[i+1]++;
if(s[i] == 'C') c[i+1]++;
if(s[i] == 'T') t[i+1]++;
}
for(int i = 1; i < n; ++i){
a[i+1] += a[i];
g[i+1] += g[i];
c[i+1] += c[i];
t[i+1] += t[i];
}
for(int i = 1; i < n+1; ++i)
{
for(int j = i+1; j <= n; ++j)
{
if(((a[j]-a[i-1]) == (t[j]-t[i-1])) && ((g[j]-g[i-1]) == (c[j]-c[i-1]))) ans++;
}
}
cout << ans << endl;
}
int main()
{
ios::sync_with_stdio(false); cin.tie(nullptr);
task();
return 0;
}
Submission Info
| Submission Time |
|
| Task |
B - DNA Sequence |
| User |
udonman |
| Language |
C++ (GCC 9.2.1) |
| Score |
400 |
| Code Size |
2827 Byte |
| Status |
AC |
| Exec Time |
41 ms |
| Memory |
3744 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
400 / 400 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
s1.txt, s2.txt, s3.txt |
| All |
01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, s1.txt, s2.txt, s3.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 01.txt |
AC |
41 ms |
3624 KiB |
| 02.txt |
AC |
39 ms |
3628 KiB |
| 03.txt |
AC |
30 ms |
3644 KiB |
| 04.txt |
AC |
27 ms |
3680 KiB |
| 05.txt |
AC |
35 ms |
3640 KiB |
| 06.txt |
AC |
33 ms |
3640 KiB |
| 07.txt |
AC |
32 ms |
3664 KiB |
| 08.txt |
AC |
34 ms |
3644 KiB |
| 09.txt |
AC |
34 ms |
3744 KiB |
| 10.txt |
AC |
35 ms |
3664 KiB |
| 11.txt |
AC |
2 ms |
3612 KiB |
| 12.txt |
AC |
34 ms |
3736 KiB |
| 13.txt |
AC |
33 ms |
3736 KiB |
| 14.txt |
AC |
36 ms |
3740 KiB |
| 15.txt |
AC |
33 ms |
3744 KiB |
| s1.txt |
AC |
2 ms |
3556 KiB |
| s2.txt |
AC |
2 ms |
3624 KiB |
| s3.txt |
AC |
2 ms |
3648 KiB |