답안 #40031

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
40031 2018-01-25T12:08:34 Z funcsr 구간 성분 (KOI15_interval) C++14
100 / 100
327 ms 28636 KB
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD (1000000009LL*1000000007LL)
const int B = 1501;
long long pB[26];
struct Encoder {
  long long u, v;
  Encoder() : u(0), v(0) {}
  void add(int k) {
    if (k < 13) u = (u + pB[k]) % MOD;
    else v = (v + pB[k-13]) % MOD;
  }
  bool operator< (const Encoder &y) const {
    if (u == y.u) return v < y.v;
    return u < y.u;
  }
  bool operator== (const Encoder &y) const {
    return u == y.u && v == y.v;
  }
};

vector<Encoder> mp[1501];
string S, T;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  pB[0] = 1;
  for (int i=1; i<26; i++) pB[i] = (1LL*B*pB[i-1]) % MOD;
  cin >> S >> T;
  rep(l, S.size()) {
    Encoder cnt;
    for (int r=l; r<S.size(); r++) {
      cnt.add(S[r]-'a');
      mp[r-l+1].pb(cnt);
    }
  }
  rep(i, 1501) sort(all(mp[i])), uniq(mp[i]);
  int m = 0;
  rep(l, T.size()) {
    Encoder cnt;
    for (int r=l; r<T.size(); r++) {
      cnt.add(T[r]-'a');
      if (binary_search(all(mp[r-l+1]), cnt)) m = max(m, r-l+1);
    }
  }
  cout << m << "\n";
  return 0;
}

Compilation message

interval.cpp: In function 'int main()':
interval.cpp:17:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define rep(i, n) for (int i=0; i<(n); i++)
                                  ^
interval.cpp:51:3: note: in expansion of macro 'rep'
   rep(l, S.size()) {
   ^
interval.cpp:53:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int r=l; r<S.size(); r++) {
                    ^
interval.cpp:17:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define rep(i, n) for (int i=0; i<(n); i++)
                                  ^
interval.cpp:60:3: note: in expansion of macro 'rep'
   rep(l, T.size()) {
   ^
interval.cpp:62:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int r=l; r<T.size(); r++) {
                    ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2220 KB Output is correct
2 Correct 0 ms 2220 KB Output is correct
3 Correct 1 ms 2352 KB Output is correct
4 Correct 1 ms 2352 KB Output is correct
5 Correct 0 ms 2352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 4084 KB Output is correct
2 Correct 15 ms 4884 KB Output is correct
3 Correct 9 ms 4884 KB Output is correct
4 Correct 6 ms 4884 KB Output is correct
5 Correct 27 ms 4884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 131 ms 12916 KB Output is correct
2 Correct 131 ms 12916 KB Output is correct
3 Correct 126 ms 12916 KB Output is correct
4 Correct 119 ms 12916 KB Output is correct
5 Correct 121 ms 12916 KB Output is correct
6 Correct 114 ms 12916 KB Output is correct
7 Correct 129 ms 12916 KB Output is correct
8 Correct 145 ms 12916 KB Output is correct
9 Correct 134 ms 12916 KB Output is correct
10 Correct 135 ms 12916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 102 ms 18960 KB Output is correct
2 Correct 308 ms 28584 KB Output is correct
3 Correct 279 ms 28584 KB Output is correct
4 Correct 194 ms 28636 KB Output is correct
5 Correct 327 ms 28584 KB Output is correct