제출 #1329658

#제출 시각아이디문제언어결과실행 시간메모리
1329658duoFancy Fence (CEOI20_fancyfence)C++20
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;

// JUST ME BRO
// TRY OLP

#define ll int64_t
#define FOR(I, L, R) for(int I(L) ; I <= (int)(R) ; ++I)
#define FOD(I, R, L) for(int I(R) ; I >= (int)(L) ; --I)
#define FOA(I, A) for(auto &I : A)
#define fi first
#define se second


const ll mod = 1e9+7;

const ll N = 2e5 + 5;

ll n;
ll H[N], W[N], suf[N],  sum ;

ll power(ll a, ll b){
    ll res = 1;
    a %= mod;
    while(b){
        if(b & 1) res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

void sub1 () {

    ll inv2 = power(2, mod - 2);

    ll x = H[1] % mod;
    ll s = sum % mod;

    ll a = x * ((x + 1) % mod) % mod * inv2 % mod;
    ll b = s * ((s + 1) % mod) % mod * inv2 % mod;

    cout << a * b % mod;
}

void sub2() {


    FOD( i  , N , 1 ){

        suf[i] = (suf[i+1] + W[i]) % mod;
    }

    ll ans = 0;

    ll inv2 = (mod + 1) / 2;

    FOR ( i , 1 , N ){

        ll ww = suf[i];

        ll ways = ww % mod * ((ww + 1) % mod) % mod;
        ways = ways * inv2 % mod;

        ans = (ans + H[i] % mod * ways % mod) % mod;
    }

    cout << ans%mod; //QUEN CACH MODULO PHEP CHIA ROI SOS

}


signed main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

   // freopen("FENCE.INP" , "r" , stdin);
  //  freopen("FENCE.OUT" , "w" , stdout);

    cin >> n ;


    bool check = false;
    bool check2 = false;

    FOR (i , 1 , n ) {
        cin >> H[i];

        if (i > 1 ) {


            if ( H[i] != H[i-1]) {

                check = true;
            }

            if ( H[i-1] > H[i])

                check2 = true;

            }
        }
    }

    FOR (i , 1 , n ) {

        cin >> W[i];
        sum+=W[i];
    }



    if (  check == false ) {


        sub1();

    }

    else if ( check2 == false ) {

        sub2();

    }

    else {

        sub2();
    }


}

컴파일 시 표준 에러 (stderr) 메시지

fancyfence.cpp:8:22: error: expected unqualified-id before 'for'
    8 | #define FOR(I, L, R) for(int I(L) ; I <= (int)(R) ; ++I)
      |                      ^~~
fancyfence.cpp:107:5: note: in expansion of macro 'FOR'
  107 |     FOR (i , 1 , n ) {
      |     ^~~
fancyfence.cpp:107:10: error: 'i' does not name a type; did you mean 'fi'?
  107 |     FOR (i , 1 , n ) {
      |          ^
fancyfence.cpp:8:37: note: in definition of macro 'FOR'
    8 | #define FOR(I, L, R) for(int I(L) ; I <= (int)(R) ; ++I)
      |                                     ^
fancyfence.cpp:8:53: error: expected unqualified-id before '++' token
    8 | #define FOR(I, L, R) for(int I(L) ; I <= (int)(R) ; ++I)
      |                                                     ^~
fancyfence.cpp:107:5: note: in expansion of macro 'FOR'
  107 |     FOR (i , 1 , n ) {
      |     ^~~
fancyfence.cpp:115:5: error: expected unqualified-id before 'if'
  115 |     if (  check == false ) {
      |     ^~
fancyfence.cpp:122:5: error: expected unqualified-id before 'else'
  122 |     else if ( check2 == false ) {
      |     ^~~~
fancyfence.cpp:128:5: error: expected unqualified-id before 'else'
  128 |     else {
      |     ^~~~
fancyfence.cpp:134:1: error: expected declaration before '}' token
  134 | }
      | ^