Submission #1804346


Source Code Expand

Copy
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const ll INF=1000000000000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

string S;
int add[100010];
vector<P> vec[50002];
bool solve(int k,int a,int b){
	//cout << k << " " << a << " " << b << endl;
	a += add[k]%26;
	b += add[S.size()-1-k]%26;
	int A = a+(S[k]-'a'); A %= 26; S[k] = 'a'+A;
	int B = b+(S[S.size()-1-k]-'a'); B %= 26; S[S.size()-1-k] = 'a'+B;
	//S[k] += a;
	//S[S.size()-1-k] += b;
	if(S.size()-1-k <= k)return true;
	if(vec[k].size() == 0){
		if(S[k] != S[S.size()-1-k]){
			return false;
		}
		return solve(k+1,a,b);
	}
	if(vec[k][0].fr == k){
		for(int i = 1 ; i < vec[k].size() ; i ++){
			if(vec[k][i].fr == k){
				P p = P(vec[k][0].sc,vec[k][i].sc);
				if(p.sc == p.fr)continue;
				if(p.sc < p.fr)swap(p.fr,p.sc);
				p.fr ++;
				vec[min(p.fr,(int)(S.size())-1-p.sc)].pb(p);
			}
			else {
				P p = P(vec[k][0].sc,vec[k][i].fr);
				if(p.fr < p.sc){
					p.fr ++;
					p.sc --;
					if(p.fr > p.sc)continue;
				}
				else swap(p.fr,p.sc);
				vec[min(p.fr,(int)(S.size())-1-p.sc)].pb(p);
			}
		}
		int d = 26-S[k]+S[S.size()-1-k]; d%=26;
		a += d;
		if(vec[k][0].sc < S.size()/2){
			if(vec[k][0].sc+1 < S.size()/2){
				add[vec[k][0].sc+1] += (26-d)%26;
			}
		}
		else add[vec[k][0].sc] +=d ;
	}
	else {
		for(int i = 1 ; i < vec[k].size() ; i ++){
			if(vec[k][i].fr == k){
				P p = P(vec[k][i].sc,vec[k][0].fr);
				if(p.fr < p.sc){
					p.fr ++;
					p.sc --;
					if(p.fr > p.sc)continue;
				}
				else swap(p.fr,p.sc);
				vec[min(p.fr,(int)(S.size())-1-p.sc)].pb(p);
			}
			else {
				P p = P(vec[k][0].fr,vec[k][i].fr);
				if(p.sc == p.fr)continue;
				if(p.sc < p.fr)swap(p.fr,p.sc);
				p.sc --;
				vec[min(p.fr,(int)(S.size())-1-p.sc)].pb(p);
			}
		}
		int d = 26+S[k]-S[S.size()-1-k]; d%=26;
		b += d;
		if(vec[k][0].fr < S.size()/2)add[vec[k][0].fr] += d;
		else{
			if(vec[k][0].fr-1 < S.size()/2){
				add[vec[k][0].fr-1] += 26-d ;
			}
		}
	}
	return solve(k+1,a,b);
}


int main(){
	static int n;
	static int l[100010],r[100010];
	cin >> S;
	scanf("%d",&n);
	rep(i,n){
		scanf("%d%d",&l[i],&r[i]);
		l[i] --;
		r[i] --;
		if(l[i] > r[i])swap(l[i],r[i]);
		vec[min(l[i],(int)(S.size())-1-r[i])].pb(P(l[i],r[i]));
	}
	if(solve(0,0,0))puts("YES");
	else puts("NO");
}
	

Submission Info

Submission Time
Task A - AKIBA
User yokozuna57
Language C++14 (GCC 5.4.1)
Score 0
Code Size 3256 Byte
Status
Exec Time 2 ms
Memory 1408 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:121:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
                ^
./Main.cpp:123:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&l[i],&r[i]);
                            ^

Test Cases

Set Name Score / Max Score Test Cases
sample 0 / 0 sample-01.txt, sample-02.txt, sample-03.txt
All 0 / 300 sample-01.txt, sample-02.txt, sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, sample-01.txt, sample-02.txt, sample-03.txt
Case Name Status Exec Time Memory
01-01.txt 2 ms 1408 KB
01-02.txt 2 ms 1408 KB
01-03.txt 2 ms 1408 KB
01-04.txt 2 ms 1408 KB
01-05.txt 2 ms 1408 KB
01-06.txt 2 ms 1408 KB
01-07.txt 2 ms 1408 KB
01-08.txt 2 ms 1408 KB
01-09.txt 2 ms 1408 KB
01-10.txt 2 ms 1408 KB
01-11.txt 2 ms 1408 KB
01-12.txt 2 ms 1408 KB
01-13.txt 2 ms 1408 KB
01-14.txt 2 ms 1408 KB
01-15.txt 2 ms 1408 KB
01-16.txt 2 ms 1408 KB
01-17.txt 2 ms 1408 KB
01-18.txt 2 ms 1408 KB
sample-01.txt 2 ms 1408 KB
sample-02.txt 2 ms 1408 KB
sample-03.txt 2 ms 1408 KB