677C - Vanya and Label - CodeForces Solution


bitmasks combinatorics implementation strings *1500

Please click on ads to support us..

Python Code:

d = {}
def f():
    arr = []
    for item in range(10):
        arr.append(str(item))
    for item in range(ord('A'), ord('Z') + 1):
        arr.append(chr(item))
    for item in range(ord('a'), ord('z') + 1):
        arr.append(chr(item))
    arr.append('-')
    arr.append('_')

    for i, item in enumerate(arr):
        d[item] = '{0:06b}'.format(i).count('0')

f()

ans = 0
s = input()
for ele in s:
    ans += d[ele]
final = 3 ** ans % (10 ** 9 + 7)
print(final)

C++ Code:

// Problem: C. Vanya and Label
// Contest: Codeforces - Codeforces Round #355 (Div. 2)
// URL: https://codeforces.com/contest/677/problem/C
// Memory Limit: 256 MB
// Time Limit: 1000 ms

/*
	Author: MikiMiku
	
	Observation:
	
	Idea: 
		
*/

#include <bits/stdc++.h>
using namespace std;

//#define int long long
#define endl '\n'

#define sza(x) ((int)x.size())
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back 
#define eb emplace_back 
#define mp make_pair

#define isOn(S, j) (S & (1 << j))
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define LSB(S) (S & (-S))
#define setAll(S, n) (S = (1 << n) - 1)
#define modulo(S, N) ((S) & (N - 1))   // returns S % N, where N is a power of 2
#define isPowerOfTwo(S) (!(S & (S - 1)))
#define nearestPowerOfTwo(S) ((int)pow(2.0, (int)((log((double)S) / log(2.0)) + 0.5)))
#define turnOffLastBit(S) ((S) & (S - 1))
#define turnOnLastZero(S) ((S) | (S + 1))
#define turnOffLastConsecutiveBits(S) ((S) & (S + 1))
#define turnOnLastConsecutiveZeroes(S) ((S) | (S - 1))

typedef complex<double> point;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

const int MAX_N = 1e5 + 5;
const ll MOD = 1e9 + 7;
const int FMOD = 998244353; 
const ll INF = 1e9;
const ld EPS = 1e-9;
const double PI=acos(-1);

#define fi first
#define se second
typedef pair<int, int> ii;  
typedef vector<ii> vii;
typedef vector<int> vi;
typedef map<int,int> mii; 

//FLOAT PRECISION SETTINGS
/*
cout.setf(ios::fixed,ios::floatfield);
cout.precision(3);
*/
//FILE IO
void setIO(string s) {
	freopen((s + ".in").c_str(), "r", stdin);
	freopen((s + ".out").c_str(), "w", stdout);
}

//........................................................................

ll fexp(ll b, ll e) {
	ll mul = b;
	ll res = 1;
	while(e > 0) {
		if(e%2==1) res *= mul;
		mul *= mul; mul %= MOD;
		res %= MOD;
		e /= 2;
	}
	return res;
}

signed main() {
	ios_base::sync_with_stdio(0);cin.tie(nullptr); cout.tie(nullptr);
	
	map<char, int> mc;
	vector<char> vc;
	int id = 0;
	for(char c = '0'; c <= '9'; ++c) vc.pb(c);
	for(char c = 'A'; c <= 'Z'; ++c) vc.pb(c);
	for(char c = 'a'; c <= 'z'; ++c) vc.pb(c);
	vc.pb('-'); vc.pb('_');
	int sz = sza(vc);
	
	for(int i = 0; i < sz; ++i) {
		mc[vc[i]] = 6 - __builtin_popcount(i);
		mc[vc[i]] = fexp(3, mc[vc[i]]);
	} 
	
	string s;
	cin >> s;
	
	ll ans = 1;
	for(auto c : s) {
		//cerr << c << " " << mc[c] << endl;
		ans *= mc[c];
		ans %= MOD;
	}
	
	cout << ans << endl;
	return 0;
}


Comments

Submit
0 Comments
More Questions

647. Palindromic Substrings
583. Delete Operation for Two Strings
518. Coin Change 2
516. Longest Palindromic Subsequence
468. Validate IP Address
450. Delete Node in a BST
445. Add Two Numbers II
442. Find All Duplicates in an Array
437. Path Sum III
436. Find Right Interval
435. Non-overlapping Intervals
406. Queue Reconstruction by Height
380. Insert Delete GetRandom O(1)
332. Reconstruct Itinerary
368. Largest Divisible Subset
377. Combination Sum IV
322. Coin Change
307. Range Sum Query - Mutable
287. Find the Duplicate Number
279. Perfect Squares
275. H-Index II
274. H-Index
260. Single Number III
240. Search a 2D Matrix II
238. Product of Array Except Self
229. Majority Element II
222. Count Complete Tree Nodes
215. Kth Largest Element in an Array
198. House Robber
153. Find Minimum in Rotated Sorted Array