Submission #1311241
Source Code Expand
#include<bits/stdc++.h>
using namespace std;
#define fRead(x) freopen(x,"r",stdin)
#define fWrite(x) freopen (x,"w",stdout)
#define LL long long
#define ULL unsigned long long
#define ff first
#define ss second
#define pb push_back
#define INF 2e16
#define PI acos(-1.0)
#define mk make_pair
#define pii pair<int,int>
#define pll pair<LL,LL>
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define min4(a,b,c,d) min(a,min(b,min(c,d)))
#define max4(a,b,c,d) max(a,max(b,max(c,d)))
#define SQR(a) ((a)*(a))
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define REP(i,b) for(int i=0;i<b;i++)
#define MEM(a,x) memset(a,x,sizeof(a))
#define ABS(x) ((x)<0?-(x):(x))
#define SORT(v) sort(v.begin(),v.end())
#define REV(v) reverse(v.begin(),v.end())
#define FastRead ios_base::sync_with_stdio(0);cin.tie(nullptr);
LL Right[100005];
LL Left[100005];
int main()
{
FastRead
string str;
cin >> str;
str.insert(str.begin(), '0');
LL cnt = 0;
for(int i = str.size()-1;i>=1;i--){
Right[i] = cnt;
if(str[i]=='D')cnt++;
}
cnt = 0;
for(int i = 1;i<str.size();i++){
Left[i] = cnt;
if(str[i]=='U')cnt++;
}
LL ans = 0;
for(int i = 1;i<str.size();i++){
LL lu = Left[i];
LL lo = (i-1) - lu;
ans += lu + 2*lo;
LL rd = Right[i];
LL ro = (str.size()-1 - i) - rd;
ans += rd + ro*2;
}
cout << ans << "\n";
// for(int i = 1;i<str.size();i++)cout << Left[i] << " ";
// cout << endl;
// for(int i = 1;i<str.size();i++)cout << Right[i] << " ";
}
Submission Info
Submission Time |
|
Task |
B - Evilator |
User |
fsshakkhor |
Language |
C++14 (GCC 5.4.1) |
Score |
400 |
Code Size |
1917 Byte |
Status |
AC |
Exec Time |
2 ms |
Memory |
2000 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
400 / 400 |
Status |
|
|
Set Name |
Test Cases |
Sample |
s1.txt, s2.txt |
All |
01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, s1.txt, s2.txt |
Case Name |
Status |
Exec Time |
Memory |
01.txt |
AC |
2 ms |
2000 KB |
02.txt |
AC |
2 ms |
2000 KB |
03.txt |
AC |
2 ms |
2000 KB |
04.txt |
AC |
2 ms |
2000 KB |
05.txt |
AC |
2 ms |
2000 KB |
06.txt |
AC |
2 ms |
2000 KB |
07.txt |
AC |
2 ms |
2000 KB |
08.txt |
AC |
2 ms |
2000 KB |
09.txt |
AC |
1 ms |
256 KB |
10.txt |
AC |
1 ms |
256 KB |
s1.txt |
AC |
1 ms |
256 KB |
s2.txt |
AC |
1 ms |
256 KB |