Submission #95614

# Submission time Handle Problem Language Result Execution time Memory
95614 2019-02-02T06:38:45 Z diamond_duke None (KOI17_shell) C++11
100 / 100
549 ms 48408 KB
#include <algorithm>
#include <cstring>
#include <cstdio>
using ll = long long;
int dp[2005][2005], arr[2005][2005], st[2005], en[2005], n;
struct BIT
{
	int seg[2005];
	BIT() { memset(seg, 0, sizeof(seg)); }
	inline void modify(int pos, int x)
	{
		for (; pos <= n; pos += pos & -pos)
			seg[pos] += x;
	}
	inline int query(int pos)
	{
		int res = 0;
		for (; pos; pos -= pos & -pos)
			res += seg[pos];
		return res;
	}
} seg[2005];
inline int query(int x, int y) { return dp[x][y] + seg[x].query(y); }
int main()
{
	// freopen("KOI2017-T4.in", "r", stdin);
	scanf("%d", &n);
	ll ans = 0;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			scanf("%d", arr[i] + j);
			dp[i][j] = std::max(dp[i - 1][j], dp[i][j - 1]) + arr[i][j];
			ans += dp[i][j];
		}
	}
	printf("%lld\n", ans);
	for (int cas = 0; cas < n; cas++)
	{
		memset(st, 0x3f, sizeof(st));
		memset(en, 0, sizeof(en));
		char tp;
		int sx, sy;
		scanf(" %c%d%d", &tp, &sx, &sy);
		int val = tp == 'U' ? 1 : -1, x = sx, y = sy;
		st[x] = en[x] = y;
		while (true)
		{
			if (y < n && std::max(query(x - 1, y + 1), query(x, y)) + val ==
					std::max(query(x - 1, y + 1), query(x, y) + val))
				y++;
			else
				x++;
			if (x > n)
				break;
			en[x] = y;
		}
		x = sx;
		y = sy;
		while (true)
		{
			if (x < n && std::max(query(x + 1, y - 1), query(x, y)) + val ==
					std::max(query(x + 1, y - 1), query(x, y) + val))
				x++;
			else
				y++;
			if (y > n || en[x] < y)
				break;
			st[x] = std::min(st[x], y);
		}
		for (int i = sx; i <= n; i++)
		{
			if (st[i] > en[i])
				continue;
			ans += (en[i] - st[i] + 1) * val;
			seg[i].modify(st[i], val);
			seg[i].modify(en[i] + 1, -val);
		}
		printf("%lld\n", ans);
	}
	return 0;
}

Compilation message

shell.cpp: In function 'int main()':
shell.cpp:27:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
shell.cpp:33:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", arr[i] + j);
    ~~~~~^~~~~~~~~~~~~~~~~~
shell.cpp:45:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %c%d%d", &tp, &sx, &sy);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 16 ms 17016 KB Output is correct
2 Correct 14 ms 17016 KB Output is correct
3 Correct 14 ms 16888 KB Output is correct
4 Correct 14 ms 17016 KB Output is correct
5 Correct 14 ms 17016 KB Output is correct
6 Correct 17 ms 17016 KB Output is correct
7 Correct 17 ms 17016 KB Output is correct
8 Correct 16 ms 16888 KB Output is correct
9 Correct 16 ms 16892 KB Output is correct
10 Correct 16 ms 17016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 227 ms 44256 KB Output is correct
2 Correct 231 ms 44160 KB Output is correct
3 Correct 240 ms 44024 KB Output is correct
4 Correct 298 ms 44024 KB Output is correct
5 Correct 282 ms 44152 KB Output is correct
6 Correct 214 ms 44024 KB Output is correct
7 Correct 224 ms 44108 KB Output is correct
8 Correct 272 ms 44024 KB Output is correct
9 Correct 274 ms 44076 KB Output is correct
10 Correct 279 ms 44152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 17016 KB Output is correct
2 Correct 14 ms 17016 KB Output is correct
3 Correct 14 ms 16888 KB Output is correct
4 Correct 14 ms 17016 KB Output is correct
5 Correct 14 ms 17016 KB Output is correct
6 Correct 17 ms 17016 KB Output is correct
7 Correct 17 ms 17016 KB Output is correct
8 Correct 16 ms 16888 KB Output is correct
9 Correct 16 ms 16892 KB Output is correct
10 Correct 227 ms 44256 KB Output is correct
11 Correct 231 ms 44160 KB Output is correct
12 Correct 240 ms 44024 KB Output is correct
13 Correct 298 ms 44024 KB Output is correct
14 Correct 282 ms 44152 KB Output is correct
15 Correct 214 ms 44024 KB Output is correct
16 Correct 224 ms 44108 KB Output is correct
17 Correct 272 ms 44024 KB Output is correct
18 Correct 274 ms 44076 KB Output is correct
19 Correct 279 ms 44152 KB Output is correct
20 Correct 295 ms 48320 KB Output is correct
21 Correct 299 ms 48204 KB Output is correct
22 Correct 299 ms 48348 KB Output is correct
23 Correct 519 ms 48336 KB Output is correct
24 Correct 533 ms 48248 KB Output is correct
25 Correct 532 ms 48376 KB Output is correct
26 Correct 222 ms 44000 KB Output is correct
27 Correct 246 ms 44064 KB Output is correct
28 Correct 325 ms 48248 KB Output is correct
29 Correct 296 ms 48292 KB Output is correct
30 Correct 512 ms 48352 KB Output is correct
31 Correct 549 ms 48408 KB Output is correct
32 Correct 213 ms 44028 KB Output is correct
33 Correct 280 ms 44024 KB Output is correct
34 Correct 16 ms 17016 KB Output is correct