Submission #1041391

#TimeUsernameProblemLanguageResultExecution timeMemory
1041391hungeazyTram (CEOI13_tram)C++17
0 / 100
19 ms29272 KiB
/* * @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 (stderr)

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);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...