답안 #946128

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
946128 2024-03-14T10:39:43 Z kokoxuya Fancy Fence (CEOI20_fancyfence) C++14
25 / 100
25 ms 3028 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define moddy 1000000007

int findRect(int height, int width, int inc)
{
	//cout << height << " " << width << " " << inc << " ";
	int ans = (height + 1) * height / 2;
	ans %= moddy;
	ans *= width;
	ans %= moddy;
	ans *= inc;
	ans %= moddy;
	//cout << ans << "\n";
	return ans;
}

int incRect(int height, int width)
{
	//cout << height << " " << width << " ";
	int ans = height * (height + 1)/2;
	ans %= moddy;
	int temp1 = ((width + 1) * width/2);
	temp1 %= moddy;
	ans *= temp1;
	ans %= moddy;
	//cout << ans << "\n";
	return ans;
}

signed main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int N;
	cin >> N;
	vector<int>heights(N + 20);
	vector<int>widths(N + 20);
	
	for (int a = 1; a <= N; a++)
	{
		cin >> heights[a];
	}
	for (int a = 1; a <= N; a++)
	{
		cin >> widths[a];
	}
	
	int ans = 0;
	queue<pair<int,int>>prevvy; //height, width
	for (int curr = 1; curr <= N; curr++)
	{
		//cout << "at rectangle " << curr << ":\n";
		int at = 0,prevwidth = 0;
		queue<pair<int,int>>curry;
		while (!prevvy.empty())
		{
			if (at == heights[curr])
			{
				break;
			}
			ans += (findRect(min(heights[curr], prevvy.front().first), prevvy.front().second, widths[curr]));
			ans -= (findRect(at,prevvy.front().second,widths[curr]));
			ans %= moddy;
			curry.push({min(heights[curr], prevvy.front().first), prevvy.front().second + widths[curr]});
			at = min(heights[curr], prevvy.front().first);
			//cout << "\n";
			prevvy.pop();
		}
		ans += incRect(heights[curr],widths[curr]);
		ans %= moddy;
		if (at != heights[curr])
		{
			curry.push({heights[curr],widths[curr]});
		}
		prevvy = curry;
	}
	
	ans %= moddy;
	cout << ans;
	//cout << " at end ";
}

Compilation message

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:54:14: warning: unused variable 'prevwidth' [-Wunused-variable]
   54 |   int at = 0,prevwidth = 0;
      |              ^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 12 ms 1764 KB Output is correct
4 Correct 25 ms 2652 KB Output is correct
5 Correct 24 ms 2808 KB Output is correct
6 Correct 22 ms 3028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 3 ms 604 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Incorrect 3 ms 604 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -