답안 #498636

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
498636 2021-12-26T02:28:35 Z RambaXGorilla Fancy Fence (CEOI20_fancyfence) C++17
12 / 100
1 ms 332 KB
#include<cstdio>
#include<algorithm>
#include<utility>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair <int,int> ii;
#define pq priority_queue
const int modNum = 1000000007;
int N;
int heights[100010];
int widths[100010];
int prefs[100010];
int smaller[100010];
pq <ii> big;
int form(int a, int b){
    int nums[] = {a, b, a + 1, b + 1};
    for(int i = 0;i < 4;i++){
        if(!(nums[i] % 2)){
            nums[i] /= 2;
        }
    }
    ll prod = 1;
    for(int i = 0;i < 4;i++){
        prod *= nums[i];
        prod %= modNum;
    }
    return prod;
}
int main(){
    scanf("%d",&N);
    for(int i = 0;i < N;i++){
        scanf("%d",&heights[i]);
    }
    heights[N] = 0;
    prefs[0] = 0;
    for(int i = 0;i < N;i++){
        scanf("%d",&widths[i]);
        prefs[i + 1] = prefs[i] + widths[i];
    }
    for(int i = 0;i < N + 1;i++){
        while(!big.empty() && big.top().first > heights[i]){
            smaller[big.top().second] = i;
            big.pop();
        }
        big.push(ii(heights[i], i));
    }
    int total = 0;
    for(int i = 0;i < N;i++){
        int bott = 0;
        if(i > 0){
            bott = heights[i - 1];
        }
        int curr = i;
        int last;
        while(curr < N){
            last = curr;
            curr = smaller[curr];
            if(heights[last] <= bott){
                break;
            }
            total += (form(heights[last], prefs[curr] - prefs[i]) - form(max(heights[curr], bott), prefs[curr] - prefs[i]) + modNum) % modNum;
            total %= modNum;
        }
    }
    printf("%d",total);
}

Compilation message

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |     scanf("%d",&N);
      |     ~~~~~^~~~~~~~~
fancyfence.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |         scanf("%d",&heights[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~
fancyfence.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         scanf("%d",&widths[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 288 KB Output is correct
2 Incorrect 1 ms 304 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 288 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 1 ms 296 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 292 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 288 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 292 KB Output is correct
2 Incorrect 1 ms 296 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 288 KB Output is correct
2 Incorrect 1 ms 304 KB Output isn't correct