# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
226289 | emil_physmath | UFO (IZhO14_ufo) | C++17 | 1628 ms | 98604 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
using namespace std;
int shots;
int n, m;
vector<vector<int> > a;
vector<int> tcol[1000'000], trow[1000'000];
void Shoot(const vector<int>& t, int v, int vl, int vr, int hei, int dir, vector<int>& ans)
{
if (ans.size() == shots) return;
if (t[v] < hei) return;
if (vl == vr)
{
ans.push_back(vr);
return;
}
int vm = (vl + vr) / 2;
if (dir == 1)
{
Shoot(t, v * 2, vl, vm, hei, dir, ans);
Shoot(t, v * 2 + 1, vm + 1, vr, hei, dir, ans);
}
else
{
Shoot(t, v * 2 + 1, vm + 1, vr, hei, dir, ans);
Shoot(t, v * 2, vl, vm, hei, dir, ans);
}
}
void Add(vector<int>& t, int v, int vl, int vr, int i, int val)
{
if (vl == vr)
{
t[v] += val;
return;
}
int vm = (vl + vr) / 2;
if (i <= vm) Add(t, v * 2, vl, vm, i, val);
else Add(t, v * 2 + 1, vm + 1, vr, i, val);
t[v] = max(t[v * 2], t[v * 2 + 1]);
}
void SetRow(int i, int v, int vl, int vr)
{
if (vl == vr)
{
a[i][vr] = trow[i][v];
return;
}
int vm = (vl + vr) / 2;
SetRow(i, v * 2, vl, vm);
SetRow(i, v * 2 + 1, vm + 1, vr);
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int qnum, anpetq;
cin >> n >> m >> shots >> qnum >> anpetq;
a.resize(n, vector<int>(m));
for (int i = 0; i < n; ++i)
trow[i].resize(4 * m);
for (int j = 0; j < m; ++j)
tcol[j].resize(4 * n);
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++j)
{
cin >> a[i][j];
Add(trow[i], 1, 0, m - 1, j, a[i][j]);
Add(tcol[j], 1, 0, n - 1, i, a[i][j]);
}
while (qnum--)
{
char dir;
int i, hei;
cin >> dir >> i >> hei;
int j = --i;
vector<int> col;
vector<int> row;
if (dir == 'W')
Shoot(trow[i], 1, 0, m - 1, hei, 1, col);
else if (dir == 'E')
Shoot(trow[i], 1, 0, m - 1, hei, -1, col);
else if (dir == 'N')
Shoot(tcol[j], 1, 0, n - 1, hei, 1, row);
else // 'S'
Shoot(tcol[j], 1, 0, n - 1, hei, -1, row);
if (dir == 'W' || dir == 'E')
for (int j: col)
{
Add(trow[i], 1, 0, m - 1, j, -1);
Add(tcol[j], 1, 0, n - 1, i, -1);
}
else
for (int i: row)
{
Add(trow[i], 1, 0, m - 1, j, -1);
Add(tcol[j], 1, 0, n - 1, i, -1);
}
}
for (int i = 0; i < n; ++i)
SetRow(i, 1, 0, m - 1);
int ans = 0;
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < m; ++j)
{
#ifdef MANSON
cerr << a[i][j] << ' ';
#endif
if (i + anpetq - 1 >= n || j + anpetq - 1 >= m) continue;
int cur = 0;
for (int di = 0; di < anpetq; ++di)
for (int dj = 0; dj < anpetq; ++dj)
cur += a[i + di][j + dj];
ans = max(ans, cur);
}
#ifdef MANSON
cerr << '\n';
#endif
}
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |