Submission #1177201

#TimeUsernameProblemLanguageResultExecution timeMemory
1177201nguynStone Arranging 2 (JOI23_ho_t1)C++20
100 / 100
95 ms13384 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define F first #define S second #define pb push_back #define pii pair<int,int> const int N = 2e5 + 5; int n; int a[N]; map<int, int> pos; int nxt[N]; signed main(){ ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0) ; if (fopen("INP.INP" ,"r")) { freopen("INP.INP" ,"r" , stdin) ; freopen("OUT.OUT" , "w" , stdout) ; } cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = n; i >= 1; i--) { if (!pos.count(a[i])) { nxt[i] = i; pos[a[i]] = i; } else { nxt[i] = pos[a[i]]; pos[a[i]] = i; } } int npos = 0; int cur = a[1]; for (int i = 1; i <= n; i++) { if (i > npos) { cout << a[i]; cur = a[i]; npos = nxt[i]; } else { if (cur == a[i]) { npos = nxt[i]; } cout << cur; } cout << '\n'; } }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen("INP.INP" ,"r" , stdin) ;
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         freopen("OUT.OUT" , "w" , stdout) ;
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...