#include<bits/stdc++.h>
#include<fstream>
using namespace std;
ifstream fin("XMAS.INP");
ofstream fout("XMAS.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ld PI = 3.14159265359;
//using u128 = __uint128_t;
//const int x[4] = {1, -1, 0, 0};
//const int y[4] = {0, 0, 1, -1};
const ll mod = 1e9 + 9;
const int mxn = 50000 + 5, mxq = 2e5 + 5, sq = 500, mxv = 2e6 + 5;
const ll inf = 1e17 + 5;
//const int base= (1 << 18);
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, d;
int to[mxn + 1], pw[4];
string s[mxn + 1];
int conv(string s){
int ans = 0;
for(int i = 0; i < sz(s); i++){
ans += to[s[i]] * pw[i];
}
return(ans);
}
namespace one{
ll cnt[mxv + 1];
void solve(){
ll res = 0;
for(int i = 1; i <= n; i++){
for(int j = 0; j < 4; j++){
char rev = s[i][j];
for(char c = '0'; c <= '9'; c++){
if(c != rev){
s[i][j] = c;
res += cnt[conv(s[i])];
s[i][j] = rev;
}
}
for(char c = 'a'; c <= 'z'; c++){
if(c != rev){
s[i][j] = c;
res += cnt[conv(s[i])];
s[i][j] = rev;
}
}
}
cnt[conv(s[i])]++;
}
cout << res;
}
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> d;
pw[0] = 1;
for(int i = 1; i < 4; i++){
pw[i] = (pw[i - 1] * 36);
}
for(char c = '0'; c <= '9'; c++)to[c] = (c - '0');
for(char c = 'a'; c <= 'z'; c++)to[c] = (c - 'a') + 10;
for(int i = 1; i <= n; i++){
cin >> s[i];
}
if(d == 1){
one::solve();
}
return(0);
}
Compilation message
pin.cpp: In function 'int conv(std::string)':
pin.cpp:33:23: warning: array subscript has type 'char' [-Wchar-subscripts]
33 | ans += to[s[i]] * pw[i];
| ^
pin.cpp: In function 'int main()':
pin.cpp:72:40: warning: array subscript has type 'char' [-Wchar-subscripts]
72 | for(char c = '0'; c <= '9'; c++)to[c] = (c - '0');
| ^
pin.cpp:73:40: warning: array subscript has type 'char' [-Wchar-subscripts]
73 | for(char c = 'a'; c <= 'z'; c++)to[c] = (c - 'a') + 10;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
4952 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2908 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
2908 KB |
Output isn't correct |
4 |
Correct |
60 ms |
5252 KB |
Output is correct |
5 |
Correct |
75 ms |
5296 KB |
Output is correct |
6 |
Incorrect |
2 ms |
2904 KB |
Output isn't correct |
7 |
Incorrect |
2 ms |
2908 KB |
Output isn't correct |
8 |
Correct |
82 ms |
5216 KB |
Output is correct |
9 |
Correct |
137 ms |
5308 KB |
Output is correct |
10 |
Incorrect |
3 ms |
2908 KB |
Output isn't correct |
11 |
Incorrect |
2 ms |
2908 KB |
Output isn't correct |
12 |
Incorrect |
3 ms |
2908 KB |
Output isn't correct |
13 |
Incorrect |
2 ms |
2908 KB |
Output isn't correct |
14 |
Incorrect |
2 ms |
2908 KB |
Output isn't correct |
15 |
Incorrect |
3 ms |
2908 KB |
Output isn't correct |
16 |
Correct |
206 ms |
16160 KB |
Output is correct |
17 |
Incorrect |
3 ms |
2908 KB |
Output isn't correct |
18 |
Incorrect |
2 ms |
2908 KB |
Output isn't correct |
19 |
Incorrect |
3 ms |
2904 KB |
Output isn't correct |
20 |
Incorrect |
3 ms |
2908 KB |
Output isn't correct |