Submission #474458

# Submission time Handle Problem Language Result Execution time Memory
474458 2021-09-18T09:52:08 Z abc864197532 Sateliti (COCI20_satellti) C++17
10 / 110
9 ms 5452 KB
/*
 *   ##   #####   ####      ####  #    #  ####
 *  #  #  #    # #    #    #    # #    # #    #
 * #    # #####  #         #    # #    # #    #
 * ###### #    # #         #    # # ## # #    #
 * #    # #    # #    #    #    # ##  ## #    #
 * #    # #####   ####      ####  #    #  ####
 */
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair <int, int>
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define info() cout << __PRETTY_FUNCTION__ << ": " << __LINE__ << endl
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
    cout << a << ' ', abc(b...);
}
template <typename T> void printv(T l, T r) {
    while (l != r) cout << *l << " \n"[++l == r];
}
template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) {
    return o >> a.X >> a.Y;
}
template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) {
    return o << '(' << a.X << ", " << a.Y << ')';
}
template <typename T> ostream& operator << (ostream& o, vector<T> a) {
    bool is = false;
    if (a.empty()) return o << "{}";
    for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;}
    return o << '}';
}
template <typename T> struct vv : vector <vector <T>> {
    vv(int n, int m, T v) : vector <vector <T>> (n, vector <T>(m, v)) {}
    vv() {}
};
template <typename T> struct vvv : vector <vv <T>> {
    vvv(int n, int m, int k, T v) : vector <vv <T>> (n, vv <T>(m, k, v)) {}
    vvv() {}
};
#ifdef Doludu
#define test(args...) info(), abc("[" + string(#args) + "]", args)
#define owo freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout); 
#else
#define test(args...) void(0)
#define owo ios::sync_with_stdio(false); cin.tie(0)
#endif
const int mod = 998244353, N = 1000001, logN = 20, K = 48763, KK = 331983854;

int main () {
    owo;
    int n, m;
    cin >> n >> m;
    vector <int> pw(n * m + 1, 1), pwinv(n * m + 1, 1);
    for (int i = 1; i <= n * m; ++i) {
        pw[i] = 1ll * pw[i - 1] * K % mod;
        pwinv[i] = 1ll * pwinv[i - 1] * KK % mod;
    }
    vector <string> s(n * 2);
    vv <int> pre(2 * n + 1, 2 * m + 1, 0);
    auto query = [&](int i, int j, int l, int r) {
        lli ans = ((long long)pre[j][r] - pre[j][l] - pre[i][r] + pre[i][l]) % mod;
        if (ans < 0) ans += mod;
        return ans * pwinv[i * m + l] % mod;
    };
    for (int i = 0; i < n; ++i) {
        cin >> s[i], s[i] += s[i], s[n + i] = s[i];
    } 
    for (int i = 0; i < 2 * n; ++i) {
        int sum = 0;
        for (int j = 0; j < 2 * m; ++j) {
            sum += 1ll * s[i][j] * pw[i * m + j] % mod;
            if (sum >= mod) {
                sum -= mod;
            }
            pre[i + 1][j + 1] = pre[i][j + 1] + sum;
            if (pre[i + 1][j + 1] >= mod) {
                pre[i + 1][j + 1] -= mod;
            }
        }
    }
    int ansl = 0, ansr = 0;
    for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) {
        if (!i && !j) continue;
        int l = 0, r = n + 1;
        while (r - l > 1) {
            int mid = l + r >> 1;
            if (query(ansl, ansl + mid, ansr, ansr + m) == query(i, i + mid, j, j + m)) {
                l = mid;
            } else {
                r = mid;
            }
        }
        if (l == n) continue;
        int mx = l;
        l = 0, r = m;
        while (r - l > 1) {
            int mid = l + r >> 1;
            if (query(ansl + mx, ansl + mx + 1, ansr, ansr + mid) == query(i + mx, i + mx + 1, j, j + mid)) {
                l = mid;
            } else {
                r = mid;
            }
        }
        if (s[ansl + mx][ansr + l] > s[i + mx][j + l]) {
            ansl = i, ansr = j;
        }
    }
    for (int i = ansl; i < ansl + n; ++i) {
        for (int j = ansr; j < ansr + m; ++j) {
            cout << s[i][j];
        }
        cout << endl;
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:94:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   94 |             int mid = l + r >> 1;
      |                       ~~^~~
Main.cpp:105:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  105 |             int mid = l + r >> 1;
      |                       ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Runtime error 9 ms 5452 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Runtime error 9 ms 5452 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -