QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#697683#9430. Left Shifting 2jiangXxinAC ✓14ms4204kbC++202.5kb2024-11-01 15:20:142024-11-01 15:20:15

Judging History

你现在查看的是最新测评结果

  • [2024-11-01 15:20:15]
  • 评测
  • 测评结果:AC
  • 用时:14ms
  • 内存:4204kb
  • [2024-11-01 15:20:14]
  • 提交

answer

// Problem: I. Left Shifting 2
// Contest: Codeforces - The 2024 ICPC Kunming Invitational Contest
// URL: https://codeforces.com/gym/105386/problem/I
// Memory Limit: 1024 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

/*
   /\__/\
  (o    o)
  /      \
 // ^  ^ \\
///      \\\
  \      /
   \____/
  /\_  _/\
 */
#include<bits/stdc++.h>

#define fir first
#define sec second
#define pb push_back
#define lowbit(X) X&(-X)
#define sz(X) (int)(X).size()
#define all(X) (X).begin(),(X).end()

#define YES cout<<"YES"<<'\n'
#define Yes cout<<"Yes"<<'\n'
#define NO cout<<"NO"<<'\n'
#define No cout<<"No"<<'\n'
#define error cout<<"-1"<<'\n'

using namespace std;
typedef long long unt;
typedef long double ld;
typedef vector<int> vt_int;
typedef vector<char> vt_char;
typedef vector<bool> vt_bool;
typedef vector<long long> vt_unt;
typedef vector<long double> vt_ld;
typedef vector<vector<int> > vvt_int;
typedef vector<vector<char> > vvt_char;
typedef vector<vector<bool> > vvt_bool;
typedef vector<vector<long long> > vvt_unt;
typedef vector<vector<long double> > vvt_ld;

const long long mod=1e9+7;
const long long INF=1152921504606846976;//(2^60)
const long long N=110000;

int solve(){
    string s;
    cin>>s;
    int n=s.size();
	set<char>S;
	for(auto e:s){
		S.insert(e);
	}
	if(sz(S)==1){
		cout<<n/2<<endl;
		return 0;
	}
	deque<char>a;
	for(auto e:s){
		a.push_back(e);
	}
	while(a.front()==a.back()){
		int x=a.front();
		a.pop_front();
		a.push_back(x);
		//ans++;
	}
	
	// for(int i=0;i<n;i++){
		// cout<<a[i]<<" ";
	// }
	// cout<<endl;
	
	for(int i=0;i<n;i++){
		int cnt=1;
		while(i+1<n&&a[i+1]==a[i]){
			cnt++;
			i++;
		}
		//cout<<i<<" "<<cnt<<endl;
		if(cnt%2==0){
			int k=i;
			while(k--){
				int x=a.front();
				a.pop_front();
				a.push_back(x);
			}
			//ans+=i-(cnt/2)+1;
			break;
		}
	}
	
	// for(int i=0;i<n;i++){
		// cout<<a[i]<<" ";
	// }
	// cout<<endl;
	
	int ans=0;
	for(int i=0;i<n;i++){
		int cnt=1;
		while(i+1<n&&a[i+1]==a[i]){
			cnt++;
			i++;
		}
		//cout<<i<<" "<<cnt<<endl;
		ans+=(cnt/2);
	}
	cout<<ans<<endl;
    return 0;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int testcase;
    testcase=1;
    cin>>testcase;
    while(testcase--){
        int flag=solve();
        
        if(flag==1) YES;
        if(flag==-1) NO;
    }
    return 0;
}


这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3584kb

input:

3
abccbbbbd
abcde
x

output:

2
0
0

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 7ms
memory: 3636kb

input:

5000
lfpbavjsmppdppkfwnyfmbdhptdswsoulrbhyjh
cfliuqnynejgnxolzbdoztclzbozqomvioszk
eiivcoqoymonrqgrjdtkts
mdcvservaxcbioopfungsgkiftchwlmtbzqgaraovjknsgiegkvdbolmeunvrxrpscnf
ujeqtidwtoikkqtygo
llma
qjfvgwrdhaazejsfgilnpmmhkefndzvyon
kzwwpdpbrudqmwmjscllnnjyoepxophcoopvfepikouinuxx
vftculoorxskpkxoz...

output:

1
0
0
0
0
0
1
4
0
0
1
1
1
1
1
3
1
0
5
6
0
0
5
2
0
1
3
2
0
3
0
1
0
1
1
0
1
4
1
3
1
0
1
5
3
0
3
0
0
1
8
1
0
6
1
2
0
1
0
0
4
1
2
4
3
1
3
2
3
1
2
1
0
0
2
0
2
2
0
4
0
5
5
0
3
0
4
1
0
2
1
0
2
0
1
6
1
2
1
3
3
3
5
2
3
0
3
5
1
3
0
0
3
0
4
5
3
2
1
1
0
0
2
0
1
1
3
3
3
1
2
0
1
1
4
3
1
3
1
1
1
2
0
1
2
0
4
0
1
1
...

result:

ok 5000 lines

Test #3:

score: 0
Accepted
time: 10ms
memory: 4164kb

input:

1
cbppzfsncqyzmuwrcvtxsciucxusskcjhaanwhqmyncytwhkubrvcqxgcehdxyewdyvpqjcmrnmlgrytrucexmmfulqbtfctehphmrzkosyvhtvjrromqncbgsjcwhmlqidkycaxyhsrduoxayntuhqubvboseeziwjvrfagsbvtxjjbexnajqapgxydwtztzbbdpoydnjipfizdfpmczgqvdmpvxbqubtygkfpdeonegfzsttirbhzkobbigwneyvtcxndfkljdvbbcfnadtfhgohfzqeidtgyandhnvb...

output:

18631

result:

ok single line: '18631'

Test #4:

score: 0
Accepted
time: 14ms
memory: 4196kb

input:

1
qokalgqjhyijyizyihdsiapbgvzxzevykavqmgqzrpjngciqcljsuplvpaziebmumatzvngwrhgsxrtcoiseihejwpewvosnrgvhoxluliuwixgxylazufebrwgfebazrkghgwbpqavehtnakmzqsetghmzoydwmeqvoplkyqngwrgktylrnaojpkvuwfsjbizedqwhfteyjobrglkhkeoxmxdgyuygawvdjhyakpkjchyxaqthrglcldevrzskdaotkbsbmnstrsxervdvmaylqxnwaecfmdszwedrdom...

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 5ms
memory: 4152kb

input:

1
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbyyqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccceeeeeeeeeeeeeeeeeeeeezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz...

output:

246800

result:

ok single line: '246800'

Test #6:

score: 0
Accepted
time: 6ms
memory: 4204kb

input:

1
yyyyyyyyyyyyyyyyyyyyyyyyhhhhhhhhaaaannnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnhhhhhhhhhhhhhhhhhhhhhhhiiiiiiiieeeeeeeeeesssssssbbbbbbbbbbiiiiiiiwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxaaaaaaaaaaaaaaaadccccckkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkc...

output:

242729

result:

ok single line: '242729'

Extra Test:

score: 0
Extra Test Passed