Submission #8776950


Source Code Expand

Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
struct StringMaster {
    string S; int N; StringMaster() {}StringMaster(string s) { init(s); }
    void init(string s) { S = s; N = S.length(); initgo(); }

    // get the nearest index for the char
    vector<int> hidari[26], migi[26];
    inline void initgo() {
        rep(c, 0, 26) { migi[c].resize(N); migi[c][N - 1] = inf; }
        rrep(i, N - 2, 0) { rep(c, 0, 26) migi[c][i] = migi[c][i + 1]; migi[S[i + 1]][i] = i + 1; }
        rep(c, 0, 26) { hidari[c].resize(N); hidari[c][0] = -1; }
        rep(i, 1, N) { rep(c, 0, 26) hidari[c][i] = hidari[c][i - 1]; hidari[S[i - 1]][i] = i - 1; }
    }
    inline int gomigi(int cu, int c) { 
		if (cu == inf) return inf;
		if (cu < 0) {
			if (S[0] == c) return 0;
			cu = 0;
		}
		return migi[c][cu];
	}
    inline int gohidari(int cu, int c) {
		if (cu < 0) return cu;
		return hidari[c][cu];
	}
};
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int N; string S;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> S;

	fore(c, S) c -= '0';
	StringMaster sm(S);

	int ans = 0;
	rep(x0, 0, 10) rep(x1, 0, 10) rep(x2, 0, 10) {
		int cu = -1;
		cu = sm.gomigi(cu, x0);
		cu = sm.gomigi(cu, x1);
		cu = sm.gomigi(cu, x2);
		if (cu < inf) ans++;
	}
	cout << ans << endl;
}





Submission Info

Submission Time
Task D - Lucky PIN
User hamayanhamayan
Language C++14 (GCC 5.4.1)
Score 400
Code Size 2584 Byte
Status
Exec Time 6 ms
Memory 6400 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt
All 400 / 400 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt, 01-corner-01.txt, 01-corner-02.txt, 01-corner-03.txt, 01-corner-04.txt, 02-random-01.txt, 02-random-02.txt, 02-random-03.txt, 02-random-04.txt, 02-random-05.txt, 02-random-06.txt, 02-random-07.txt, 03-random-x-01.txt, 03-random-x-02.txt, 03-random-x-03.txt, 04-expand-01.txt, 04-expand-02.txt, 04-expand-03.txt, 04-expand-04.txt, 04-expand-05.txt, 04-expand-06.txt, 04-expand-07.txt, 04-expand-08.txt, 05-limiting-01.txt, 05-limiting-02.txt, 05-limiting-03.txt, 05-limiting-04.txt, 05-limiting-05.txt, 05-limiting-06.txt, 05-limiting-07.txt, 05-limiting-08.txt
Case Name Status Exec Time Memory
00-sample-01.txt 1 ms 256 KB
00-sample-02.txt 1 ms 256 KB
00-sample-03.txt 1 ms 256 KB
01-corner-01.txt 1 ms 256 KB
01-corner-02.txt 1 ms 256 KB
01-corner-03.txt 1 ms 256 KB
01-corner-04.txt 1 ms 256 KB
02-random-01.txt 1 ms 256 KB
02-random-02.txt 1 ms 256 KB
02-random-03.txt 1 ms 256 KB
02-random-04.txt 1 ms 256 KB
02-random-05.txt 1 ms 256 KB
02-random-06.txt 1 ms 256 KB
02-random-07.txt 6 ms 6400 KB
03-random-x-01.txt 3 ms 2304 KB
03-random-x-02.txt 4 ms 4352 KB
03-random-x-03.txt 6 ms 6400 KB
04-expand-01.txt 6 ms 6272 KB
04-expand-02.txt 6 ms 6272 KB
04-expand-03.txt 6 ms 6272 KB
04-expand-04.txt 6 ms 6400 KB
04-expand-05.txt 6 ms 6400 KB
04-expand-06.txt 6 ms 6400 KB
04-expand-07.txt 6 ms 6272 KB
04-expand-08.txt 6 ms 6272 KB
05-limiting-01.txt 6 ms 6400 KB
05-limiting-02.txt 6 ms 6400 KB
05-limiting-03.txt 6 ms 6400 KB
05-limiting-04.txt 6 ms 6400 KB
05-limiting-05.txt 6 ms 6272 KB
05-limiting-06.txt 6 ms 6272 KB
05-limiting-07.txt 6 ms 6272 KB
05-limiting-08.txt 6 ms 6272 KB