답안 #466715

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
466715 2021-08-20T13:50:46 Z ivan_tudor Cubeword (CEOI19_cubeword) C++14
84 / 100
270 ms 8984 KB
#include<bits/stdc++.h>
using namespace std;
vector<string> v[11];
const int MOD = 998244353;
void add(int &x, long long y){
  y%=MOD;
  x+=y;
  if(x>=MOD)
    x-=MOD;
  if(x<0)
    x+=MOD;
}
int codes(char c){
  if(c >= 'a' && c <= 'z')
    return c - 'a';
  else if( c >= 'A' && c<= 'Z')
    return c - 'A' + 'z' - 'a' + 1;
  else if(c >= '0' && c <= '9'){
    return c - 'a' + 'Z' - 'A' + 1 + 'z' - 'a' + 1;
  }
  assert(0);
  return -1;
}
const int SIGMA = 'Z' - 'A' + 1 + 'z' - 'a' + 1 + '9' - '0' + 1 + 1;
int nw[SIGMA][SIGMA];
int nr[SIGMA][SIGMA][SIGMA];
int coef(int l1, int l2, int l3, int l4){
  if(l1 == l4)
    return 1;
  if(l1 == l3 || l2 == l4)
    return 4;
  if(l1 == l2 && l3 == l4)
    return 6;
  if(l1 == l2 || l2 == l3 || l3 == l4)
    return 12;
  return 24;
}
int main()
{
  //freopen(".in","r",stdin);
  ios::sync_with_stdio(false);
  cin.tie(0),cout.tie(0);
  int n;
  cin>>n;
  for(int i = 1; i <=n; i++){
    string s;
    cin>>s;
    int len = s.size();
    v[len].push_back(s);
    reverse(s.begin(), s.end());
    v[len].push_back(s);
  }
  int ans = 0;
  for(int len = 3; len<=10; len++){
    // doar ce e unic
    sort(v[len].begin(), v[len].end());
    auto last = unique(v[len].begin(), v[len].end());
    v[len].erase(last, v[len].end());
    for(string x:v[len]){
      nw[codes(x[0])][codes(x[x.size() - 1])]++;
    }
    for(int l1 = 0; l1 < SIGMA; l1++){
      for(int l2 = l1; l2 < SIGMA; l2++){
        for(int l3 = l2; l3 < SIGMA; l3++){
          for(int l4 = 0; l4 < SIGMA; l4++){
            long long ad = 1LL * nw[l4][l1] * nw[l4][l2] % MOD * nw[l4][l3] % MOD;
            if(add)
              add(nr[l1][l2][l3], ad);
          }
        }
      }
    }
    for(int l1 = 0; l1 < SIGMA; l1++){
      for(int l2 = l1; l2 < SIGMA; l2++){
        for(int l3 = l2; l3 < SIGMA; l3++){
          for(int l4 = l3; l4 < SIGMA; l4++){
            long long nwc = 1LL *nr[l1][l2][l3] * nr[l1][l2][l4] % MOD * nr[l1][l3][l4] % MOD * nr[l2][l3][l4] % MOD;
            if(nwc)
              add(ans, 1LL *nwc * coef(l1, l2, l3, l4));
          }
        }
      }
    }
    memset(nr, 0, sizeof(nr));
    memset(nw, 0, sizeof(nw));
  }
  cout<<ans;
  return 0;
}

Compilation message

cubeword.cpp: In function 'int main()':
cubeword.cpp:67:16: warning: the address of 'void add(int&, long long int)' will never be NULL [-Waddress]
   67 |             if(add)
      |                ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 230 ms 8784 KB Output is correct
2 Correct 270 ms 8784 KB Output is correct
3 Correct 216 ms 8708 KB Output is correct
4 Correct 226 ms 8836 KB Output is correct
5 Correct 234 ms 8832 KB Output is correct
6 Correct 220 ms 8984 KB Output is correct
7 Correct 226 ms 8812 KB Output is correct
8 Correct 234 ms 8728 KB Output is correct
9 Correct 224 ms 8804 KB Output is correct
10 Correct 250 ms 8848 KB Output is correct
11 Correct 230 ms 8912 KB Output is correct
12 Correct 229 ms 8840 KB Output is correct
13 Correct 249 ms 8840 KB Output is correct
14 Correct 227 ms 8640 KB Output is correct
15 Correct 221 ms 8808 KB Output is correct
16 Correct 225 ms 8764 KB Output is correct
17 Correct 222 ms 8808 KB Output is correct
18 Correct 218 ms 8692 KB Output is correct
19 Correct 222 ms 8788 KB Output is correct
20 Correct 237 ms 8804 KB Output is correct
21 Correct 227 ms 8828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 230 ms 8784 KB Output is correct
2 Correct 270 ms 8784 KB Output is correct
3 Correct 216 ms 8708 KB Output is correct
4 Correct 226 ms 8836 KB Output is correct
5 Correct 234 ms 8832 KB Output is correct
6 Correct 220 ms 8984 KB Output is correct
7 Correct 226 ms 8812 KB Output is correct
8 Correct 234 ms 8728 KB Output is correct
9 Correct 224 ms 8804 KB Output is correct
10 Correct 250 ms 8848 KB Output is correct
11 Correct 230 ms 8912 KB Output is correct
12 Correct 229 ms 8840 KB Output is correct
13 Correct 249 ms 8840 KB Output is correct
14 Correct 227 ms 8640 KB Output is correct
15 Correct 221 ms 8808 KB Output is correct
16 Correct 225 ms 8764 KB Output is correct
17 Correct 222 ms 8808 KB Output is correct
18 Correct 218 ms 8692 KB Output is correct
19 Correct 222 ms 8788 KB Output is correct
20 Correct 237 ms 8804 KB Output is correct
21 Correct 227 ms 8828 KB Output is correct
22 Correct 261 ms 8408 KB Output is correct
23 Correct 216 ms 8388 KB Output is correct
24 Correct 221 ms 8540 KB Output is correct
25 Correct 226 ms 8652 KB Output is correct
26 Correct 219 ms 8600 KB Output is correct
27 Correct 224 ms 8708 KB Output is correct
28 Correct 216 ms 8436 KB Output is correct
29 Correct 215 ms 8480 KB Output is correct
30 Correct 216 ms 8500 KB Output is correct
31 Correct 218 ms 8400 KB Output is correct
32 Correct 220 ms 8492 KB Output is correct
33 Correct 261 ms 8500 KB Output is correct
34 Correct 253 ms 8600 KB Output is correct
35 Correct 228 ms 8708 KB Output is correct
36 Correct 232 ms 8600 KB Output is correct
37 Correct 223 ms 8532 KB Output is correct
38 Correct 227 ms 8648 KB Output is correct
39 Correct 221 ms 8624 KB Output is correct
40 Correct 218 ms 8680 KB Output is correct
41 Correct 217 ms 8656 KB Output is correct
42 Correct 215 ms 8496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 230 ms 8784 KB Output is correct
2 Correct 270 ms 8784 KB Output is correct
3 Correct 216 ms 8708 KB Output is correct
4 Correct 226 ms 8836 KB Output is correct
5 Correct 234 ms 8832 KB Output is correct
6 Correct 220 ms 8984 KB Output is correct
7 Correct 226 ms 8812 KB Output is correct
8 Correct 234 ms 8728 KB Output is correct
9 Correct 224 ms 8804 KB Output is correct
10 Correct 250 ms 8848 KB Output is correct
11 Correct 230 ms 8912 KB Output is correct
12 Correct 229 ms 8840 KB Output is correct
13 Correct 249 ms 8840 KB Output is correct
14 Correct 227 ms 8640 KB Output is correct
15 Correct 221 ms 8808 KB Output is correct
16 Correct 225 ms 8764 KB Output is correct
17 Correct 222 ms 8808 KB Output is correct
18 Correct 218 ms 8692 KB Output is correct
19 Correct 222 ms 8788 KB Output is correct
20 Correct 237 ms 8804 KB Output is correct
21 Correct 227 ms 8828 KB Output is correct
22 Correct 261 ms 8408 KB Output is correct
23 Correct 216 ms 8388 KB Output is correct
24 Correct 221 ms 8540 KB Output is correct
25 Correct 226 ms 8652 KB Output is correct
26 Correct 219 ms 8600 KB Output is correct
27 Correct 224 ms 8708 KB Output is correct
28 Correct 216 ms 8436 KB Output is correct
29 Correct 215 ms 8480 KB Output is correct
30 Correct 216 ms 8500 KB Output is correct
31 Correct 218 ms 8400 KB Output is correct
32 Correct 220 ms 8492 KB Output is correct
33 Correct 261 ms 8500 KB Output is correct
34 Correct 253 ms 8600 KB Output is correct
35 Correct 228 ms 8708 KB Output is correct
36 Correct 232 ms 8600 KB Output is correct
37 Correct 223 ms 8532 KB Output is correct
38 Correct 227 ms 8648 KB Output is correct
39 Correct 221 ms 8624 KB Output is correct
40 Correct 218 ms 8680 KB Output is correct
41 Correct 217 ms 8656 KB Output is correct
42 Correct 215 ms 8496 KB Output is correct
43 Correct 233 ms 8464 KB Output is correct
44 Correct 226 ms 8476 KB Output is correct
45 Correct 223 ms 8352 KB Output is correct
46 Correct 238 ms 8576 KB Output is correct
47 Correct 229 ms 8532 KB Output is correct
48 Correct 227 ms 8852 KB Output is correct
49 Correct 229 ms 8864 KB Output is correct
50 Correct 219 ms 8972 KB Output is correct
51 Correct 226 ms 8672 KB Output is correct
52 Correct 226 ms 8460 KB Output is correct
53 Correct 223 ms 8440 KB Output is correct
54 Correct 225 ms 8700 KB Output is correct
55 Correct 227 ms 8960 KB Output is correct
56 Correct 224 ms 8548 KB Output is correct
57 Correct 225 ms 8736 KB Output is correct
58 Correct 224 ms 8856 KB Output is correct
59 Correct 224 ms 8716 KB Output is correct
60 Correct 226 ms 8840 KB Output is correct
61 Correct 231 ms 8492 KB Output is correct
62 Correct 226 ms 8736 KB Output is correct
63 Correct 229 ms 8848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 230 ms 8784 KB Output is correct
2 Correct 270 ms 8784 KB Output is correct
3 Correct 216 ms 8708 KB Output is correct
4 Correct 226 ms 8836 KB Output is correct
5 Correct 234 ms 8832 KB Output is correct
6 Correct 220 ms 8984 KB Output is correct
7 Correct 226 ms 8812 KB Output is correct
8 Correct 234 ms 8728 KB Output is correct
9 Correct 224 ms 8804 KB Output is correct
10 Correct 250 ms 8848 KB Output is correct
11 Correct 230 ms 8912 KB Output is correct
12 Correct 229 ms 8840 KB Output is correct
13 Correct 249 ms 8840 KB Output is correct
14 Correct 227 ms 8640 KB Output is correct
15 Correct 221 ms 8808 KB Output is correct
16 Correct 225 ms 8764 KB Output is correct
17 Correct 222 ms 8808 KB Output is correct
18 Correct 218 ms 8692 KB Output is correct
19 Correct 222 ms 8788 KB Output is correct
20 Correct 237 ms 8804 KB Output is correct
21 Correct 227 ms 8828 KB Output is correct
22 Correct 261 ms 8408 KB Output is correct
23 Correct 216 ms 8388 KB Output is correct
24 Correct 221 ms 8540 KB Output is correct
25 Correct 226 ms 8652 KB Output is correct
26 Correct 219 ms 8600 KB Output is correct
27 Correct 224 ms 8708 KB Output is correct
28 Correct 216 ms 8436 KB Output is correct
29 Correct 215 ms 8480 KB Output is correct
30 Correct 216 ms 8500 KB Output is correct
31 Correct 218 ms 8400 KB Output is correct
32 Correct 220 ms 8492 KB Output is correct
33 Correct 261 ms 8500 KB Output is correct
34 Correct 253 ms 8600 KB Output is correct
35 Correct 228 ms 8708 KB Output is correct
36 Correct 232 ms 8600 KB Output is correct
37 Correct 223 ms 8532 KB Output is correct
38 Correct 227 ms 8648 KB Output is correct
39 Correct 221 ms 8624 KB Output is correct
40 Correct 218 ms 8680 KB Output is correct
41 Correct 217 ms 8656 KB Output is correct
42 Correct 215 ms 8496 KB Output is correct
43 Correct 233 ms 8464 KB Output is correct
44 Correct 226 ms 8476 KB Output is correct
45 Correct 223 ms 8352 KB Output is correct
46 Correct 238 ms 8576 KB Output is correct
47 Correct 229 ms 8532 KB Output is correct
48 Correct 227 ms 8852 KB Output is correct
49 Correct 229 ms 8864 KB Output is correct
50 Correct 219 ms 8972 KB Output is correct
51 Correct 226 ms 8672 KB Output is correct
52 Correct 226 ms 8460 KB Output is correct
53 Correct 223 ms 8440 KB Output is correct
54 Correct 225 ms 8700 KB Output is correct
55 Correct 227 ms 8960 KB Output is correct
56 Correct 224 ms 8548 KB Output is correct
57 Correct 225 ms 8736 KB Output is correct
58 Correct 224 ms 8856 KB Output is correct
59 Correct 224 ms 8716 KB Output is correct
60 Correct 226 ms 8840 KB Output is correct
61 Correct 231 ms 8492 KB Output is correct
62 Correct 226 ms 8736 KB Output is correct
63 Correct 229 ms 8848 KB Output is correct
64 Incorrect 252 ms 8732 KB Output isn't correct
65 Halted 0 ms 0 KB -