답안 #539035

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
539035 2022-03-18T10:14:31 Z cpp219 Palinilap (COI16_palinilap) C++17
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
#define debug(y) cout<<y,exit(0)
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 1e5 + 9;
const ll base = 31;
const ll mod = 1e9 + 7;

ll n,Hash[N][2],pw[N],kill[2][N],creat[N][26],ans;
string s[2];

void performHash(){
    for (ll i = 1;i <= n;i++)
        for (ll j = 0;j < 2;j++){
            Hash[i][j] = Hash[i - 1][j]*base + s[j][i] - 'a' + 1;
            Hash[i][j] %= mod;
        }
}

ll GetHash(ll l,ll r,ll c){
    //debug(pw[1]);
    //debug(pw[r - l + 1]);
    return (Hash[r][c] - Hash[l - 1][c]*pw[r - l + 1] + mod*mod)%mod;
}

bool IsPalin(ll l,ll r){
    //debug(GetHash(l,r,0));
    //debug(Hash[3][1]);
    //debug(GetHash(n - r + 1,n - l + 1,1));
    return GetHash(l,r,0) == GetHash(n - r + 1,n - l + 1,1);
}

int main(){
    ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
    #define task "tst"
    if (fopen(task".inp","r")){
        freopen(task".inp","r",stdin);
        //freopen(task".out","w",stdout);
    }
    cin>>s[0]; n = s[0].size();
    s[1] = s[0]; reverse(s[1].begin(),s[1].end());
    s[0] = " " + s[0]; s[1] = " " + s[1];
    performHash(); pw[0] = 1;
    for (ll i = 1;i <= n;i++) pw[i] = (pw[i - 1]*base) % mod;
    //debug(IsPalin(1,3));
    for (ll i = 1;i <= n;i++)
        for (ll j = i;j <= i + 1;j++){
            if (j > n || s[0][i] != s[0][j]) continue;
            ll l = 1,h = min(i,n - j + 1),m;
            while(l <= h){
                m = (l + h)/2;
                if (IsPalin(i - m + 1,j + m - 1)) l = m + 1;
                else h = m - 1;
            }
            ll rad = h; ans += rad; //cout<<i<<" "<<j<<" "<<rad<<"\n";
            kill[0][i]++; kill[0][i - rad]--;
            kill[1][j]++; kill[1][j + rad]--;
            if (i - rad <= 0 || j + rad > n) continue;
            l = 0; h = min(i - rad,n - j - rad + 1);
            ll x = i - rad,y = j + rad;
            while(l <= h){
                m = (l + h)/2;
                ll kq1 = GetHash(x - m,x - 1,0);
                ll kq2 = GetHash(n - y - m + 1,n - y,1);
                if (kq1 == kq2) l = m + 1;
                else h = m - 1;
            }
            creat[x][s[0][y] - 'a'] += h + 1;
            creat[y][s[0][x] - 'a'] += h + 1;
        }
    //for (ll i = 1;i <= n;i++) cout<<kill[0][i]<<" "; cout<<"\n";
    for (ll i = 2;i <= n;i++) kill[1][i] += kill[1][i - 1];
    //for (ll i = 1;i <= n;i++) cout<<kill[0][i]<<" "; return 0;
    for (ll i = 2;i <= n;i++) kill[1][i] += kill[1][i - 1];

    for (ll i = n - 1;i > 0;i--) kill[0][i] += kill[0][i + 1];

    for (ll i = n - 1;i > 0;i--) kill[0][i] += kill[0][i + 1];
    //for (ll i = 1;i <= n;i++) cout<<kill[0][i]<<" "; return 0;
    //debug(creat[2][2]);
    for (ll i = 1;i <= n;i++){
        ll kq = kill[0][i + 1] + kill[1][i - 1],mx = 0;
        for (ll j = 0;j < 26;j++) mx = max(mx,creat[i][j]);
        ans = max(ans,kq + mx + 1); //cout<<i<<" "<<kq + mx<<"\n";
    }
    cout<<ans;
}
/// be confident

Compilation message

palinilap.cpp:13:32: error: 'long long int kill [2][100009]' redeclared as different kind of entity
   13 | ll n,Hash[N][2],pw[N],kill[2][N],creat[N][26],ans;
      |                                ^
In file included from /usr/include/c++/10/csignal:42,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:43,
                 from palinilap.cpp:1:
/usr/include/signal.h:112:12: note: previous declaration 'int kill(__pid_t, int)'
  112 | extern int kill (__pid_t __pid, int __sig) __THROW;
      |            ^~~~
palinilap.cpp: In function 'int main()':
palinilap.cpp:60:19: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   60 |             kill[0][i]++; kill[0][i - rad]--;
      |                   ^
palinilap.cpp:60:22: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   60 |             kill[0][i]++; kill[0][i - rad]--;
      |                      ^
palinilap.cpp:60:22: warning: ISO C++ forbids incrementing a pointer of type 'int (*)(__pid_t, int) noexcept' {aka 'int (*)(int, int) noexcept'} [-Wpointer-arith]
   60 |             kill[0][i]++; kill[0][i - rad]--;
      |             ~~~~~~~~~^
palinilap.cpp:60:22: error: lvalue required as increment operand
   60 |             kill[0][i]++; kill[0][i - rad]--;
      |                      ^
palinilap.cpp:60:33: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   60 |             kill[0][i]++; kill[0][i - rad]--;
      |                                 ^
palinilap.cpp:60:42: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   60 |             kill[0][i]++; kill[0][i - rad]--;
      |                                          ^
palinilap.cpp:60:42: warning: ISO C++ forbids decrementing a pointer of type 'int (*)(__pid_t, int) noexcept' {aka 'int (*)(int, int) noexcept'} [-Wpointer-arith]
   60 |             kill[0][i]++; kill[0][i - rad]--;
      |                           ~~~~~~~~~~~~~~~^
palinilap.cpp:60:42: error: lvalue required as decrement operand
   60 |             kill[0][i]++; kill[0][i - rad]--;
      |                                          ^
palinilap.cpp:61:19: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   61 |             kill[1][j]++; kill[1][j + rad]--;
      |                   ^
palinilap.cpp:61:22: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   61 |             kill[1][j]++; kill[1][j + rad]--;
      |                      ^
palinilap.cpp:61:22: warning: ISO C++ forbids incrementing a pointer of type 'int (*)(__pid_t, int) noexcept' {aka 'int (*)(int, int) noexcept'} [-Wpointer-arith]
   61 |             kill[1][j]++; kill[1][j + rad]--;
      |             ~~~~~~~~~^
palinilap.cpp:61:22: error: lvalue required as increment operand
   61 |             kill[1][j]++; kill[1][j + rad]--;
      |                      ^
palinilap.cpp:61:33: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   61 |             kill[1][j]++; kill[1][j + rad]--;
      |                                 ^
palinilap.cpp:61:42: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   61 |             kill[1][j]++; kill[1][j + rad]--;
      |                                          ^
palinilap.cpp:61:42: warning: ISO C++ forbids decrementing a pointer of type 'int (*)(__pid_t, int) noexcept' {aka 'int (*)(int, int) noexcept'} [-Wpointer-arith]
   61 |             kill[1][j]++; kill[1][j + rad]--;
      |                           ~~~~~~~~~~~~~~~^
palinilap.cpp:61:42: error: lvalue required as decrement operand
   61 |             kill[1][j]++; kill[1][j + rad]--;
      |                                          ^
palinilap.cpp:76:37: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   76 |     for (ll i = 2;i <= n;i++) kill[1][i] += kill[1][i - 1];
      |                                     ^
palinilap.cpp:76:40: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   76 |     for (ll i = 2;i <= n;i++) kill[1][i] += kill[1][i - 1];
      |                                        ^
palinilap.cpp:76:51: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   76 |     for (ll i = 2;i <= n;i++) kill[1][i] += kill[1][i - 1];
      |                                                   ^
palinilap.cpp:76:58: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   76 |     for (ll i = 2;i <= n;i++) kill[1][i] += kill[1][i - 1];
      |                                                          ^
cc1plus: warning: pointer to a function used in arithmetic [-Wpointer-arith]
palinilap.cpp:76:42: error: invalid operands of types 'int(__pid_t, int) noexcept' {aka 'int(int, int) noexcept'} and 'int (*)(__pid_t, int) noexcept' {aka 'int (*)(int, int) noexcept'} to binary 'operator+'
   76 |     for (ll i = 2;i <= n;i++) kill[1][i] += kill[1][i - 1];
      |                               ~~~~~~~~~~~^~~~~~~~~~~~~~~~~
palinilap.cpp:76:42: note:   in evaluation of 'operator+=(int(__pid_t, int) noexcept {aka int(int, int) noexcept}, int (*)(__pid_t, int) noexcept {aka int (*)(int, int) noexcept})'
palinilap.cpp:78:37: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   78 |     for (ll i = 2;i <= n;i++) kill[1][i] += kill[1][i - 1];
      |                                     ^
palinilap.cpp:78:40: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   78 |     for (ll i = 2;i <= n;i++) kill[1][i] += kill[1][i - 1];
      |                                        ^
palinilap.cpp:78:51: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   78 |     for (ll i = 2;i <= n;i++) kill[1][i] += kill[1][i - 1];
      |                                                   ^
palinilap.cpp:78:58: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   78 |     for (ll i = 2;i <= n;i++) kill[1][i] += kill[1][i - 1];
      |                                                          ^
cc1plus: warning: pointer to a function used in arithmetic [-Wpointer-arith]
palinilap.cpp:78:42: error: invalid operands of types 'int(__pid_t, int) noexcept' {aka 'int(int, int) noexcept'} and 'int (*)(__pid_t, int) noexcept' {aka 'int (*)(int, int) noexcept'} to binary 'operator+'
   78 |     for (ll i = 2;i <= n;i++) kill[1][i] += kill[1][i - 1];
      |                               ~~~~~~~~~~~^~~~~~~~~~~~~~~~~
palinilap.cpp:78:42: note:   in evaluation of 'operator+=(int(__pid_t, int) noexcept {aka int(int, int) noexcept}, int (*)(__pid_t, int) noexcept {aka int (*)(int, int) noexcept})'
palinilap.cpp:80:40: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   80 |     for (ll i = n - 1;i > 0;i--) kill[0][i] += kill[0][i + 1];
      |                                        ^
palinilap.cpp:80:43: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   80 |     for (ll i = n - 1;i > 0;i--) kill[0][i] += kill[0][i + 1];
      |                                           ^
palinilap.cpp:80:54: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   80 |     for (ll i = n - 1;i > 0;i--) kill[0][i] += kill[0][i + 1];
      |                                                      ^
palinilap.cpp:80:61: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   80 |     for (ll i = n - 1;i > 0;i--) kill[0][i] += kill[0][i + 1];
      |                                                             ^
cc1plus: warning: pointer to a function used in arithmetic [-Wpointer-arith]
palinilap.cpp:80:45: error: invalid operands of types 'int(__pid_t, int) noexcept' {aka 'int(int, int) noexcept'} and 'int (*)(__pid_t, int) noexcept' {aka 'int (*)(int, int) noexcept'} to binary 'operator+'
   80 |     for (ll i = n - 1;i > 0;i--) kill[0][i] += kill[0][i + 1];
      |                                  ~~~~~~~~~~~^~~~~~~~~~~~~~~~~
palinilap.cpp:80:45: note:   in evaluation of 'operator+=(int(__pid_t, int) noexcept {aka int(int, int) noexcept}, int (*)(__pid_t, int) noexcept {aka int (*)(int, int) noexcept})'
palinilap.cpp:82:40: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   82 |     for (ll i = n - 1;i > 0;i--) kill[0][i] += kill[0][i + 1];
      |                                        ^
palinilap.cpp:82:43: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   82 |     for (ll i = n - 1;i > 0;i--) kill[0][i] += kill[0][i + 1];
      |                                           ^
palinilap.cpp:82:54: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   82 |     for (ll i = n - 1;i > 0;i--) kill[0][i] += kill[0][i + 1];
      |                                                      ^
palinilap.cpp:82:61: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   82 |     for (ll i = n - 1;i > 0;i--) kill[0][i] += kill[0][i + 1];
      |                                                             ^
cc1plus: warning: pointer to a function used in arithmetic [-Wpointer-arith]
palinilap.cpp:82:45: error: invalid operands of types 'int(__pid_t, int) noexcept' {aka 'int(int, int) noexcept'} and 'int (*)(__pid_t, int) noexcept' {aka 'int (*)(int, int) noexcept'} to binary 'operator+'
   82 |     for (ll i = n - 1;i > 0;i--) kill[0][i] += kill[0][i + 1];
      |                                  ~~~~~~~~~~~^~~~~~~~~~~~~~~~~
palinilap.cpp:82:45: note:   in evaluation of 'operator+=(int(__pid_t, int) noexcept {aka int(int, int) noexcept}, int (*)(__pid_t, int) noexcept {aka int (*)(int, int) noexcept})'
palinilap.cpp:86:23: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   86 |         ll kq = kill[0][i + 1] + kill[1][i - 1],mx = 0;
      |                       ^
palinilap.cpp:86:30: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   86 |         ll kq = kill[0][i + 1] + kill[1][i - 1],mx = 0;
      |                              ^
cc1plus: warning: pointer to a function used in arithmetic [-Wpointer-arith]
palinilap.cpp:86:40: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   86 |         ll kq = kill[0][i + 1] + kill[1][i - 1],mx = 0;
      |                                        ^
palinilap.cpp:86:47: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   86 |         ll kq = kill[0][i + 1] + kill[1][i - 1],mx = 0;
      |                                               ^
cc1plus: warning: pointer to a function used in arithmetic [-Wpointer-arith]
palinilap.cpp:86:32: error: invalid operands of types 'int(__pid_t, int) noexcept' {aka 'int(int, int) noexcept'} and 'int(__pid_t, int) noexcept' {aka 'int(int, int) noexcept'} to binary 'operator+'
   86 |         ll kq = kill[0][i + 1] + kill[1][i - 1],mx = 0;
      |                 ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~
      |                              |                |
      |                              |                int(__pid_t, int) noexcept {aka int(int, int) noexcept}
      |                              int(__pid_t, int) noexcept {aka int(int, int) noexcept}
palinilap.cpp:87:35: error: 'mx' was not declared in this scope
   87 |         for (ll j = 0;j < 26;j++) mx = max(mx,creat[i][j]);
      |                                   ^~
palinilap.cpp:88:28: error: 'mx' was not declared in this scope
   88 |         ans = max(ans,kq + mx + 1); //cout<<i<<" "<<kq + mx<<"\n";
      |                            ^~
palinilap.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~