QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#168104 | #7109. Traveling on the Axis | shixiaodai# | AC ✓ | 6ms | 5832kb | C++20 | 1.7kb | 2023-09-07 21:33:31 | 2023-09-07 21:33:32 |
Judging History
answer
#include<iostream>
#include<bits/stdc++.h>
#include<queue>
#include<cmath>
#include<cstring>
#include<algorithm>
#define e exp(1)
#define fi first
#define se second
using namespace std;
#define pii pair<ll,ll>
#define ll long long
#define FR(i,j,k) for(int i=j;i<=k;i++)
#define Fl(i,j,k) for(int i=j;i>=k;i--)
#define me(a) memset(a,0,sizeof(a))
#define all(a) a.begin(),a.end()
priority_queue < ll, vector<ll>, greater<ll> > qq;
priority_queue < ll, vector<ll>, less<ll> > pq;
struct node {
int x, y, ans;
inline bool operator > (const node &a )const {
return x > a.x;
}
} kk;
const ll md = 1e9 + 7;
double pi = acos(-1.0);
const ll N = 2e7 + 10;
const ll M = 1e7 + 10;
const double eps = 1e-6;
ll ksm(ll a, ll b) {
ll r = 1;
while (b) {
if (b & 1)r = r * a % md;
a = a * a % md;
b /= 2;
}
return r;
}
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1, y = 0;
return a;
}
ll d = exgcd(b, a % b, y, x);
y -= a / b * x;
return d;
}
ll n, m, l, r, k = 0;
string s;
ll a[N];
inline void solve() {
cin>>s;
n=s.size();
ll ans=0,sum=0;
for(int i=1;i<=n;i++){
if(i==1){
if(s[i-1]=='1'){
a[1]=1;
}else a[1]=2;
}else {
if(s[i-1]==s[i-2]){
a[i]=a[i-1]+2;
}else a[i]=a[i-1]+1;
}sum+=a[i];
}
//cout<<sum<<" ";
ans=sum;
for(int i=2;i<=n;i++){
if(s[i-2]=='0'){
sum-=2;
sum-=(2*(n-i+1));
ans+=sum;
}else {
if(s[i-1]=='0'){
sum-=1;
ans+=sum;
}else {
sum-=1;
sum-=(2*(n-i+1));
ans+=sum;
}
}
}cout<<ans<<"\n";
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
int __ = 1;
cin >> __;
while (__--) {
solve();
}
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3568kb
input:
3 101 011 11010
output:
12 15 43
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 6ms
memory: 5832kb
input:
6107 1010101 010110100110101 1010 1010101010010101010 101011 0101101011010101010 0101101011 11011010101 010 1011010 10110101010101010100 010101010110101 10101010101011 0101010101010101011 00101010011000 1010101010010110110 01010101001010101010 101010101010101 100100101010101010 01 011 0101010100101 ...
output:
96 889 24 1515 69 1567 279 345 14 106 1702 791 621 1447 764 1615 1755 736 1333 6 15 542 44 1689 1515 140 833 497 596 24 1640 694 462 30 425 14 1041 1446 96 504 124 75 560 970 771 945 6 1 321 137 786 720 206 769 46 103 225 74 554 2 100 529 260 207 197 2 197 1041 140 857 207 1 74 1604 41 343 1041 14 1...
result:
ok 6107 lines
Extra Test:
score: 0
Extra Test Passed