Submission #2243205


Source Code Expand

#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
string str;
int S[MAX_N];
pi D[MAX_N];

void solve() {
	cin >> str;
	N = sz(str);
	rep(i, 0, 26) {
		memset(S, 0, sizeof(S));
		rep(j, 0, N) {
			if(str[j] - 'a' == i) {
				S[j + 1]++;
			}
			else S[j + 1]--;
		}
		D[0] = pi(0, 0);
		rep(j, 0, N) {
			S[j + 1] += S[j];
			D[j + 1] = pi(S[j + 1], j + 1);
		}
		rer(j, N + 1, 1) {
			MAX(D[j - 1], D[j]);
		}
		// debug(vi(S, S + N + 1));
		// debug(vector<pi>(D, D + N + 1));
		rep(j, 0, N - 1) {
			pi p2 = D[j + 2];
			if(p2.fst - S[j] > 0) {
				cout << j + 1 << " " << p2.sec << "\n";
				return;
			}
		}
	}
	cout << "-1 -1\n";
	
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}

Submission Info

Submission Time
Task D - Unbalanced
User omochana2
Language C++14 (GCC 5.4.1)
Score 400
Code Size 2543 Byte
Status AC
Exec Time 21 ms
Memory 2000 KB

Judge Result

Set Name Sample Sub1 Sub2
Score / Max Score 0 / 0 200 / 200 200 / 200
Status
AC × 2
AC × 14
AC × 24
Set Name Test Cases
Sample 0_01, 0_02
Sub1 0_01, 0_02, 1_03, 1_04, 1_05, 1_06, 1_07, 1_08, 1_09, 1_10, 1_11, 1_12, 1_13, 1_14
Sub2 0_01, 0_02, 1_03, 1_04, 1_05, 1_06, 1_07, 1_08, 1_09, 1_10, 1_11, 1_12, 1_13, 1_14, 2_15, 2_16, 2_17, 2_18, 2_19, 2_20, 2_21, 2_22, 2_23, 2_24
Case Name Status Exec Time Memory
0_01 AC 2 ms 1024 KB
0_02 AC 2 ms 1024 KB
1_03 AC 2 ms 1024 KB
1_04 AC 2 ms 1024 KB
1_05 AC 2 ms 1024 KB
1_06 AC 2 ms 1024 KB
1_07 AC 2 ms 1024 KB
1_08 AC 2 ms 1024 KB
1_09 AC 2 ms 1024 KB
1_10 AC 2 ms 1024 KB
1_11 AC 2 ms 1024 KB
1_12 AC 2 ms 1024 KB
1_13 AC 2 ms 1024 KB
1_14 AC 2 ms 1024 KB
2_15 AC 19 ms 2000 KB
2_16 AC 19 ms 2000 KB
2_17 AC 18 ms 2000 KB
2_18 AC 17 ms 2000 KB
2_19 AC 11 ms 2000 KB
2_20 AC 7 ms 2000 KB
2_21 AC 3 ms 2000 KB
2_22 AC 18 ms 2000 KB
2_23 AC 20 ms 2000 KB
2_24 AC 21 ms 2000 KB