답안 #1041391

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1041391 2024-08-02T02:37:21 Z hungeazy 전차 (CEOI13_tram) C++17
0 / 100
19 ms 29272 KB
/*
* @Author: hungeazy
* @Date:   2024-08-02 09:20:31
* @Last Modified by:   hungeazy
* @Last Modified time: 2024-08-02 09:37:11
*/
#include <bits/stdc++.h>
// #pragma GCC optimize("O3")  
// #pragma GCC optimize("unroll-loops")  
// #pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")  
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long
#define ull unsigned long long
#define sz(x) x.size()
#define sqr(x) (1LL * (x) * (x))
#define all(x) x.begin(), x.end()
#define fill(f,x) memset(f,x,sizeof(f))
#define FOR(i,l,r) for(int i=l;i<=r;i++)
#define FOD(i,r,l) for(int i=r;i>=l;i--)
#define ii pair<int,int>
#define iii pair<int,ii>
#define di pair<ii,ii>
#define vi vector<int>
#define vii vector<ii>
#define mii map<int,int>
#define fi first
#define se second
#define pb push_back
#define MOD 1000000007
#define __lcm(a,b) (1ll * ((a) / __gcd((a), (b))) * (b))
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define MASK(i) (1LL << (i))
#define c_bit(i) __builtin_popcountll(i)
#define BIT(x,i) ((x) & MASK(i))
#define SET_ON(x,i) ((x) | MASK(i))
#define SET_OFF(x,i) ((x) & ~MASK(i))
#define oo 1e18
#define name ""
#define endl '\n'
#define time() cerr << endl << "-------------Time:" << 1000.0 * clock() / CLOCKS_PER_SEC << "ms.";
template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }
const int N = (int)1e6+10, M = (int)2e3+10;
int n,q;

namespace sub12 {

	int sz = 0,d[M][M];
	ii save[N];
	bool check[M][M];

	int DIST(ii a, ii b)
	{
		return sqr(a.fi-b.fi)+sqr(a.se-b.se);
	}

	ii calc()
	{
		if (!sz) return {1,0};
		FOR(i,1,n)
			FOR(j,0,1) d[i][j] = oo;
		ii pos = {0,0};
		FOR(i,1,n)
		{
			FOR(j,0,1)
				if (!check[i][j])
				{
					if (pos.fi) d[i][j] = min(d[i][j],DIST({i,j},{pos.fi,0}));
					if (pos.se) d[i][j] = min(d[i][j],DIST({i,j},{pos.se,1}));
					if (check[i][j^1]) d[i][j] = 1;
				}
			if (check[i][0]) pos.fi = i;
			if (check[i][1]) pos.se = i; 
		}
		pos = {0,0};
		int ans = -oo;
		FOD(i,n,1)
		{
			FOR(j,0,1)
				if (!check[i][j])
				{
					if (pos.fi) d[i][j] = min(d[i][j],DIST({i,j},{pos.fi,0}));
					if (pos.se) d[i][j] = min(d[i][j],DIST({i,j},{pos.se,1}));
					maximize(ans,d[i][j]);
				}
			if (check[i][0]) pos.fi = i;
			if (check[i][1]) pos.se = i; 
		}
		FOR(i,1,n)
			FOR(j,0,1)
				if (!check[i][j] and ans == d[i][j]) return {i,j};
	}

	void solve(void)
	{
		int pos = 0;
		while (q--)
		{
			char type;
			cin >> type;
			if (type == 'E')
			{
				save[++pos] = calc();
				check[save[pos].fi][save[pos].se] = true;
				cout << save[pos].fi << " " << save[pos].se+1 << endl;
				++sz;
			}
			else 
			{
				int x;
				cin >> x;
				++pos;
				check[save[pos].fi][save[pos].se] = false;
				--sz;
			}
		}
	}	
	
}

signed main()
{
    fast;
    if (fopen(name".inp","r"))
    {
    	freopen(name".inp","r",stdin);
    	freopen(name".out","w",stdout);
    }
    cin >> n >> q;
    if (n <= 2e3 and q <= 2e3) sub12::solve();
    time();
    return 0;
}
// ██░ ██  █    ██  ███▄    █   ▄████
//▓██░ ██▒ ██  ▓██▒ ██ ▀█   █  ██▒ ▀█▒
//▒██▀▀██░▓██  ▒██░▓██  ▀█ ██▒▒██░▄▄▄░
//░▓█ ░██ ▓▓█  ░██░▓██▒  ▐▌██▒░▓█  ██▓
//░▓█▒░██▓▒▒█████▓ ▒██░   ▓██░░▒▓███▀▒
// ▒ ░░▒░▒░▒▓▒ ▒ ▒ ░ ▒░   ▒ ▒  ░▒   ▒
// ▒ ░▒░ ░░░▒░ ░ ░ ░ ░░   ░ ▒░  ░   ░
// ░  ░░ ░ ░░░ ░ ░    ░   ░ ░ ░ ░   ░
// ░  ░  ░   ░              ░       ░

Compilation message

tram.cpp: In function 'std::pair<long long int, long long int> sub12::calc()':
tram.cpp:94:2: warning: control reaches end of non-void function [-Wreturn-type]
   94 |  }
      |  ^
tram.cpp: In function 'int main()':
tram.cpp:128:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  128 |      freopen(name".inp","r",stdin);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
tram.cpp:129:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  129 |      freopen(name".out","w",stdout);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 6748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 6728 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 19 ms 29264 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 19 ms 29272 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -