Dataset Viewer
Auto-converted to Parquet Duplicate
id
int64
251M
307M
language
stringclasses
11 values
verdict
stringclasses
119 values
source
stringlengths
0
60.3k
problem_id
stringclasses
500 values
type
stringclasses
2 values
difficulty
stringclasses
4 values
291,582,075
Python 3
OK
def solve(): n = int(input()) h = map(int, input().split()) m = {} for i in h: m[i] = m.get(i, 0) + 1 print(n - max(m.values())) t = int(input()) for i in range(t): solve()
2031A
right_submission
none
291,615,319
Python 3
OK
from collections import Counter tc = int(input()) for _ in range(tc): n = int(input()) v = list(map(int, input().split())) freq = Counter(v) max_frequency = max(freq.values()) print(n - max_frequency)
2031A
right_submission
none
300,368,503
PyPy 3-64
OK
for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) f={} for i in a: if i in f: f[i]+=1 else: f[i]=1 mx=max(f.values()) print(n-mx)
2031A
right_submission
none
297,915,599
Java 8
OK
import java.util.Scanner; public class Penchik_and_modern_monument{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(),min=sc.nextInt(),l=1,m=1; for(int i=1;i<n;i++){ int a=sc.nextInt(); if(a==min)l++; else{ m=Math.max(m,l); l=1; } min=a; } System.out.println(n-Math.max(m,l)); } } }
2031A
right_submission
none
291,618,956
Java 21
OK
import java.util.*; public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); int t = s.nextInt(); while(t-- > 0){ int n = s.nextInt(); int a[] = new int[n]; int min = -1, ans = 0; for(int i = 0;i < n; i++){ a[i] = s.nextInt(); } if(n == 1){ System.out.println("0"); continue; } int dp[] = new int[n]; for(int i = 1;i < n; i++){ dp[i] = 1; for (int j = 0; j < i; j++) { if (a[i] >= a[j]) { // dp[i] = Math.max(dp[i], dp[j] + 1); dp[i]++; } } } for(int i = 0; i < n; i++){ ans = Math.max(ans, dp[i]); // System.out.println(dp[i]); } System.out.println(n - ans); } } }
2031A
right_submission
none
291,587,816
Java 8
OK
import java.util.*; import java.io.*; import static java.lang.Math.*; import java.util.stream.Collectors; @SuppressWarnings("unused") public class Tej { public static void tej(FastIO sc) { int n = sc.nextInt(); int[] a = new int[n]; for(int i=0; i<n; i++) a[i] = sc.nextInt(); int max=1; for(int i=0; i<n-1; i++) { int tmp=1; while(i<n-1 && a[i]==a[i+1]) { tmp++; i++; } max=Math.max(max, tmp); } System.out.println(n-max); } public static void main(String[] args) { FastIO sc = new FastIO(); int t = sc.nextInt(); while(t-->0) { tej(sc); } sc.close(); } } class FastIO extends PrintWriter { private InputStream stream; private byte[] buf = new byte[1 << 16]; private int pChar; private int iChars; public FastIO() { this(System.in, System.out); } public FastIO(InputStream i, OutputStream o) { super(o); stream = i; } public FastIO(String i, String o) throws IOException { super(new FileWriter(o)); stream = new FileInputStream(i); } private int nextByte() { if (iChars == -1) { throw new InputMismatchException(); } if (pChar >= iChars) { pChar = 0; try { iChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (iChars == -1) { return -1; } } return buf[pChar++]; } public String next() { int c; do { c = nextByte(); } while (c <= ' '); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = nextByte(); } while (c > ' '); return res.toString(); } public int nextInt() { int c; do { c = nextByte(); } while (c <= ' '); int sgn = 1; if (c == '-') { sgn = -1; c = nextByte(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res = 10 * res + c - '0'; c = nextByte(); } while (c > ' '); return res * sgn; } public long nextLong() { long c; do { c = nextByte(); } while (c <= ' '); long sgn = 1; if (c == '-') { sgn = -1; c = nextByte(); } long res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res = 10 * res + c - '0'; c = nextByte(); } while (c > ' '); return res * sgn; } public double nextDouble() { return Double.parseDouble(next()); } }
2031A
right_submission
none
292,881,421
C++17 (GCC 7-32)
OK
#include <bits/stdc++.h> #define ll long long #define pii pair<int,int> #define pll pair<long long , long long> #define vi vector<int> using namespace std; ll M = 1000000007; int MM = 998244353 ; ll MMM = 1e18 + 4; ll powpow(ll a, ll b) { if(b==1) return a; ll x = powpow(a,b/2)%M; if(b%2) return (((a*x)%M)*x)%M; return (x*x)%M; } bool compareRowSize(const std::vector<int>& a, const std::vector<int>& b) { return a.size() > b.size(); } bool cmp(pair<pair<int,int>,int>& a , pair<pair<int,int>,int>&b) { if(a.first.first == b.first.first) { return a.second > b.second ; } return a.first.first<b.first.first; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin>>t; while(t--) { map<int,int>mp; int n ; cin>>n; vi a(n); for(auto&x : a) { cin>>x; mp[x]++; } int ans = 0 ; for(auto& x: mp) ans = max(ans, x.second); cout<< n - ans <<"\n"; } }
2031A
right_submission
none
293,987,520
C++20 (GCC 13-64)
OK
#include <iostream> #include <vector> #include <algorithm> #include <numeric> #include <cmath> #include <string> #include <chrono> #include <deque> #include<climits> #include <set> #include <map> #include <ctime> #include<random> #include <queue> #include <stack> #include <unordered_map> #include<unordered_set> #define mod 1000000007 #define MOD 998244353 #define pb push_back #define ff first #define ss second #define int long long int #define rep(i, n) for (int i = 0; i < (n); i++) template<class T, class U> inline bool chmin(T& a, const U& b) { if (a > b) { a = b; return true; } return false; } // const int m=2e5; // typedef long long int ll; using namespace std; typedef pair<int,int> pt; typedef vector<int> vi; const int N = 1e5 + 5; // vi fact(N,1); // vi rev(N,1); vi fact={1}; vi rev={1}; // fact[0]=1; // vector<int> v; // vector<int> a(300000); // vector<int> arr; // // vi a(100); // // typedef long long ll; // vector<int> dp; // vector<bool> used; // vector<vector<int>> sl; // ll n; // vector<pair<ll,ll>> a(N); // int mn[N]; // #define int long long // typedef vector<long long> vll; int setBitNumber(int n) { if (n == 0) return 0; int msb = 0; n = n / 2; while (n != 0) { n = n / 2; msb++; } return (1ll << msb); } int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } // // Function to return LCM of two numbers // long long lcm(ll a, ll b) // { // return (a / gcd(a, b)) * b; // } // void dfs(int node){ // vis[node]=1; // // val[node]=0; // for(auto it:adj[node]){ // int b= it.first,d=it.second; // if(!vis[b]){ // val[b]=val[node]+d; // dfs(b); // } // } // } int findGCD(vector<int> &arr, int n) { int result = arr[0]; for (int i = 1; i < n; i++) { result = gcd(arr[i], result); if(result == 1) { return 1; } } return result; } // bool comp(int a, int b) // { // return (a < b); // } bool comp(const pair<pt, int>& a, const pair<pt, int>& b) { if (a.first.ff != b.first.ff) return (a.first.ff < b.first.ff); else return (a.ff.second > b.ff.second); } int findlcm(vector<int> &arr, int n) { // Initialize result // vector<int> ans(n); int ans = arr[0]; // ans contains LCM of arr[0], ..arr[i] // after i'th iteration, for (int i = 1; i < n; i++) ans = (((arr[i] * ans)) / (gcd(arr[i], ans))); return ans; } vector<int> findlcm1(vector<int> &arr, int n) { // Initialize result vector<int> ans(n); ans[0] = arr[0]; // ans contains LCM of arr[0], ..arr[i] // after i'th iteration, for (int i = 1; i < n; i++) ans[i] = (((arr[i] * ans[i-1])) / (gcd(arr[i], ans[i-1]))); return ans; } int mex(vector<int> &arr, int N) { // sort the array sort(arr.begin(), arr.end()); int mex = 0; for (int idx = 0; idx < N; idx++) { if (arr[idx] == mex) { // Increment mex mex += 1; } } // Return mex as answer return mex; } // int dfs(int node,vi & vis,vector<vi> &adj){ // vis[node]=1; // int size=1; // for(int it:adj[node]){ // if(!vis[it]){ // size+=dfs(it,vis,adj); // } // } // return size; // } // Function to perform DFS and check for cycle bool dfs(int node, vector<vector<int>>& adj, vector<bool>& visited, vector<bool>& recStack) { // Mark the current node as visited and part of the recursion stack visited[node] = true; recStack[node] = true; // Recur for all the vertices adjacent to this vertex for (int neighbor : adj[node]) { // If the adjacent node is not visited, then recur on it if (!visited[neighbor] && dfs(neighbor, adj, visited, recStack)) { return true; } // If an adjacent node is visited and in the recursion stack, then there is a cycle else if (recStack[neighbor]) { return true; } } // Remove the node from the recursion stack recStack[node] = false; return false; } // Function to detect a cycle in a directed graph bool hasCycle(int V, vector<vector<int>>& adj) { vector<bool> visited(V, false); vector<bool> recStack(V, false); // Call the recursive helper function to detect cycle in different DFS trees for (int i = 0; i < V; i++) { if (!visited[i] && dfs(i, adj, visited, recStack)) { return true; } } return false; } int modcal(int n,int k){ int ans=n; for(int i=0;i<k-1;i++){ ans=(ans*n)%mod; } return ans; } int getSum(int n) { int sum = 0; while (n != 0) { sum = sum + n % 10; n = n / 10; } return sum; } int countFreq(string& pat, string& txt) { int M = pat.length(); int N = txt.length(); int res = 0; /* A loop to slide pat[] one by one */ for (int i = 0; i <= N - M; i++) { /* For current index i, check for pattern match */ int j; for (j = 0; j < M; j++) if (txt[i + j] != pat[j]) break; // if pat[0...M-1] = txt[i, i+1, ...i+M-1] if (j == M) { res++; } } return res; } int rangeBitwiseOr(int a, int b) { // If a is equal to b, the OR result is just a (or b) if (a == b) { return a; } // Initialize result to 0 int result = 0; // Iterate over bits from most significant to least significant for (int bit = 31; bit >= 0; --bit) { // Check if a and b have different bits at the current position if ((a & (1 << bit)) != (b & (1 << bit))) { // If they differ, set all bits to the right to 1 result = (1 << (bit + 1)) - 1; break; } } // OR result with a to include higher significant bits from a result |= a; // OR result with b to include higher significant bits from b result |= b; return result; } // [1,3,6,1,2,1] int Zeroes(int n) { int count = 0; while (n % 10 == 0) { count++; n /= 10; } return count; } int Digits(int n) { int count = 0; while (n != 0) { n /= 10; ++count; } return count; } class Solution { private: bool checkCycle(int node, vector < int > adj[], int vis[], int dfsVis[]) { vis[node] = 1; dfsVis[node] = 1; for (auto it: adj[node]) { if (!vis[it]) { if (checkCycle(it, adj, vis, dfsVis)) return true; } else if (dfsVis[it]) { return true; } } dfsVis[node] = 0; return false; } public: bool isCyclic(int N, vector < int > adj[]) { int vis[N], dfsVis[N]; for(int i = 0; i < N; i++){ vis[i] = 0; dfsVis[i] = 0; } for (int i = 0; i < N; i++) { if (!vis[i]) { // cout << i << endl; if (checkCycle(i, adj, vis, dfsVis)) { // cout << i << endl; return true; } } } return false; } }; void addEdge(vector < int > adj[], int u, int v) { adj[u].push_back(v); } int pow_mod(int x, int p,int p1) { if (p == 0) { return 1; } if (p % 2 == 0) { int y = pow_mod(x, p / 2,p1); return (y * y) % p1; } return (x * pow_mod(x, p - 1,p1)) % p1; } int inv(int x,int p,int p1) { return pow_mod(x, p - 2,p1); } // vector<int> fact = {1}; int cnk(int n, int k,int p) { int res = fact[n]; res = (res * rev[k]) % p; res = (res * rev[n-k]) % p; return res; } vector<int>Zfunc(string& str){ int n=str.size(); vector<int>z(n); int l=0,r=0; for(int i=1;i<n;i++){ if(i<=r){ z[i]=min(r-i+1,z[i-l]); } while(i+z[i]<n&&str[z[i]]==str[i+z[i]]){ z[i]++; } if(i+z[i]-1>r){ l=i; r=i+z[i]-1; } } return z; } int check(vector<int>&z,int len){ int n=z.size(); int cnt=1; for(int i=len;i<n;){ if(z[i]>=len){ cnt++; i+=len; }else{ i++; } } return cnt; } int query(int u,int v){ u++,v++; cout<<"? "<<u<<" "<<v<<endl; cout.flush(); int x; cin>>x; x--; return x; } int floorSqrt(int n) { if (n == 0 || n == 1) { return n; // The square root of 0 or 1 is itself } int start = 1, end = n, result = 0; while (start <= end) { int mid = start + (end - start) / 2; // Calculate mid point to prevent overflow // Check if mid*mid is equal to n if (mid <= n / mid) { // Equivalent to mid * mid <= n to avoid overflow result = mid; // Update the result start = mid + 1; // Look for a larger value } else { end = mid - 1; // Look for a smaller value } } return result; } // struct Compare { // bool operator()(const std::array<int, 3>& a, const std::array<int, 3>& b) const { // // Compare lexicographically (order-wise) // if (a[0] != b[0]) // return a[0] < b[0]; // Compare the first elements // else if (a[1] != b[1]) // return a[1] < b[1]; // Compare the second elements // else // return a[2] < b[2]; // Compare the third elements // } // }; // prime no 1,299,827 for hash // mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count()); int rndsum(vi & a,int k,int cnt){ int n=a.size()-1; // if(cnt==0) return 0; if(k+cnt<=n+1){ return a[cnt+k-1]-a[k-1]; } else{ return a[n]-a[k-1]+a[cnt-(n-k+1)]; } } void dfs(int u,vector<vector<pt>> &adj,vi &vis,vi &ans){ vis[u]=1; for(auto it:adj[u]){ int v=it.ff; int w=it.ss; if(!vis[v]){ vis[v]=1; ans[v]=ans[u]+w; dfs(v,adj,vis,ans); } } } int digit(int a, int b) { return a / ((int)pow(10, b - 1)) % 10; } void solve(){ int n; cin>>n; vi a(51,0); int ans=0; rep(i,n) { int x; cin>>x; a[x]++; ans=max(ans,a[x]); } cout<<n-ans<<endl; // cout<<ans<<endl; } signed main() { // Write C++ code here ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin>>t; while(t--){ solve(); } // cout << log2(RNG()) << endl; // return 0; }
2031A
right_submission
none
291,577,066
C++20 (GCC 13-64)
OK
/** * author: tourist * created: 15.11.2024 04:35:20 **/ #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "algo/debug.h" #else #define debug(...) 42 #endif int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int tt; cin >> tt; while (tt--) { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } map<int, int> freq; int mx = 0; for (int x : a) { freq[x] += 1; mx = max(mx, freq[x]); } cout << n - mx << '\n'; } return 0; }
2031A
right_submission
none
293,196,579
C++23 (GCC 14-64, msys2)
OK
#include <bits/stdc++.h> using i64 = long long; using u64 = unsigned long long; using u32 = unsigned; using u128 = unsigned __int128; void solve() { int n; std::cin >> n; std::vector<int> h(n); for (int i = 0; i < n; i++) { std::cin >> h[i]; } int ans = 0; for (int l = 0, r = 0; l < n; l = r) { while (r < n && h[l] == h[r]) { r++; } ans = std::max(ans, r - l); } ans = n - ans; std::cout << ans << "\n"; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int t; std::cin >> t; while (t--) { solve(); } return 0; }
2031A
right_submission
none
291,583,500
C++23 (GCC 14-64, msys2)
OK
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> typedef long long ll; typedef long double ld; typedef unsigned long long ull; #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> #define all(vec) vec.rbegin(), vec.rend() #define cin(v) for (auto& i : v) cin >> i #define cout(v) for (auto& i : v) cout << i << ' '; cout << "\n" #define Ceil(a, b) ((a / b) + (a % b ? 1 : 0)) #define MOD 1000000007 #define fr first #define sc second using namespace __gnu_pbds; using namespace std; void initialize_io() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.in", "r", stdin); freopen("output.out", "w", stdout); #endif } void solve(){ ll n; cin >> n; vector <ll> v(n); map <ll, ll> mp; for (auto&i : v){ cin >> i; mp[i]++; } ll mx = 0; for (auto&[_, i]:mp){ mx = max(mx, i); } cout << n - mx << "\n"; } int main(){ initialize_io(); int T = 1; cin >> T; while (T--){ solve(); } return 0; }
2031A
right_submission
none
291,601,945
C++17 (GCC 7-32)
WRONG_ANSWER on test 2
#include <iostream> using namespace std; int f[51]; int main() { int t,i,n,j,a,x; cin >> t; for (i=0; i<t; i++){ cin >> n; x=0; for (j=0; j<n; j++){ cin >> a; f[a]++; x=max(x, f[a]); } cout << n-x << '\n'; for (j=0; j<n; j++) f[j]=0; } return 0; }
2031A
wrong_submission
easy
302,464,193
C++20 (GCC 13-64)
WRONG_ANSWER on test 2
#include <iostream> using namespace std; int main() { int t; cin>>t; for (int i=0;i<t;i++) { int n; cin>>n; int h[n]; for (int j=0;j<n;j++) { cin>>h[j]; } if(n==1) cout<<0<<endl; else if(n==2) cout<<1<<endl; else if (h[n/2]==h[n/2+1]==h[n/2-1]) cout<<n-3<<endl; else if ((h[n/2]==h[n/2+1])||(h[n/2]==h[n/2-1])) cout<<n-2<<endl; else cout<<n-1<<endl; } return 0; }
2031A
wrong_submission
easy
302,696,674
C++20 (GCC 13-64)
WRONG_ANSWER on test 2
#include <iostream> using namespace std; int main (){ int t; cin >> t; while (t--) { int n; cin >> n; int a[n + 1]; a[0] = -1; int x = 1; int y = 1; for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i] == a[i - 1]) { y++; if (y > x) x = y; } } cout << n - x << endl; } }
2031A
wrong_submission
easy
291,650,754
Python 3
WRONG_ANSWER on test 2
a=int(input()) for i in range(a): b=int(input()) c=list(map(int,input().split())) if c==(sorted(c))[::-1]: d=len(set(c)) if d==len(c): print(len(c)-1) else: print(len(c)-d) else: print(0)
2031A
wrong_submission
easy
296,419,107
Python 3
WRONG_ANSWER on test 2
t = int(input()) for _ in range(t): n = int(input()) lst = list(map(int, input().split())) count = 0 for i in range(n - 1): if lst[i] > lst[i + 1]: count += 1 print(count)
2031A
wrong_submission
easy
291,644,011
Python 3
WRONG_ANSWER on test 2
a=int(input()) for i in range(a): b=int(input()) c=list(map(int,input().split())) d=0 for e in range(1,b): if c[e]<c[e-1]: d+=1 print(d)
2031A
wrong_submission
easy
291,623,142
Java 21
WRONG_ANSWER on test 2
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); for (int i = 0; i < t; i++) { int n = scanner.nextInt(); int[] heights = new int[n]; for (int j = 0; j < n; j++) { heights[j] = scanner.nextInt(); } int operations = 0; int lastHeight = 0; for (int j = 0; j < n; j++) { if (heights[j] < lastHeight) { operations++; } else { lastHeight = heights[j]; } } System.out.println(operations); } scanner.close(); } }
2031A
wrong_submission
easy
293,078,205
Java 21
WRONG_ANSWER on test 2
import java.util.Scanner; public class PMMonument { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int[] h= new int[n]; for(int i = 0; i < n; i++ ){ h[i] = sc.nextInt(); } int operations = 0; for (int i = n - 2; i >= 0; i--) { if (h[i] > h[i + 1]) { operations = h[i] - h[i + 1]; h[i] = h[i + 1]; } } System.out.println(operations); } sc.close(); } }
2031A
wrong_submission
easy
291,581,922
C++20 (GCC 13-64)
WRONG_ANSWER on test 2
/* Author : kmv a.k.a kzhi K41 IT CHV */ #include <bits/stdc++.h> using namespace std; //#define int long long #define ll long long #define FOR(i,a,b) for (int i = a ; i <= b; ++ i) #define FOD(i,a,b) for (int i = a; i >= b; -- i) #define BIT(mask,i) ((mask >> i) & 1) #define MASK(i) (1ll << (i)) #define OFFBIT(mask,i) (mask &~(1ll<<(i))) #define ONBIT(mask,i) (mask | (1ll << (i))) #define lg2(x) (63 - __builtin_clzll(x)) #define c_bit __builtin_popcountll #define vi vector < int > #define all(a) a.begin(), a.end() #define pb push_back #define ii pair<int,int> #define fi first #define se second #define openfile(TASK) if (fopen(TASK".inp","r"))\ {freopen(TASK".inp","r",stdin);freopen(TASK".out","w",stdout);} #define endl '\n' #define Faster ios_base::sync_with_stdio(false); \ cin.tie(0); cout.tie(0); #define mid(l,r) ((l + r) >> 1) #define left(id) (id << 1) #define right(id) ((id << 1) | 1) #define ci const int template <class X, class Y> bool maximize(X &a, const Y &b){if(a < b) return a = b, true;return false;} template <class X, class Y> bool minimize(X &a, const Y &b){if(a > b) return a = b, true;return false;} const int N = 55; int n, a[N]; void SOLVE(){ cin >> n; FOR (i, 1, n) cin >> a[i]; int cnt = 0; FOR (i, 2, n) if (a[i] < a[i - 1]){ a[i] = a[i - 1]; cnt ++; } cout << cnt << endl; } signed main(){ Faster openfile("test") int q = 1; cin >> q; while (q --){ SOLVE(); } return 0; }
2031A
wrong_submission
medium
292,435,140
C++23 (GCC 14-64, msys2)
WRONG_ANSWER on test 2
#include <bits/stdc++.h> #define int long long using namespace std; int32_t main() { int t; cin>>t; while(t--){ int n; cin>>n; vector <int> vec; for (int i=0; i<n; i++){ int x=0; cin>>x; vec.push_back(x); } sort(vec.begin(), vec.end()); vector <int> vec1(vec[n-1],0); for (int i=0; i<n; i++){ vec1[vec[i]-1]++; } sort(vec1.begin(), vec1.end()); int count=0; for (int i=0; i<vec1.size(); i++){ if (vec1[vec1.size()-1]==1){ count=1; break; } if (vec1[i]==vec1[vec1.size()-1] && vec1[vec1.size()-1]!=1){ count+=vec1[i]; } } if (n==1){ cout<<0<<endl; } else{ cout<<vec.size()-count<<endl; } } }
2031A
wrong_submission
medium
291,624,407
Python 3
WRONG_ANSWER on test 2
def min_operations_to_non_decreasing(n, heights): operations = 0 max_height = heights[0] # Iterate through array starting from second element for i in range(1, n): # If current height is less than previous maximum # We need to increase it to at least max_height if heights[i] < max_height: operations += 1 else: # Update max_height if current height is larger max_height = heights[i] return operations # Read number of test cases t = int(input()) for _ in range(t): # Read number of pillars n = int(input()) # Read heights array heights = list(map(int, input().split())) # Print minimum operations needed print(min_operations_to_non_decreasing(n, heights))
2031A
wrong_submission
medium
291,653,494
Python 3
WRONG_ANSWER on test 2
t=int(input()) while t>0: t-=1 n=int(input()) li=list(map(int,input().split(" "))) s=set(li) print(len(s)-1)
2031A
wrong_submission
medium
293,929,166
Java 21
WRONG_ANSWER on test 2
import java.util.*; import java.io.*; import java.math.*; public class sub { /* * /\_/\ (= ._.) / > \> */ static int mod = 998244353; public static void main(String args[]) { int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int a[] = new int[n]; for(int i = 0;i<n;i++)a[i]=sc.nextInt(); int ans = 0; for(int i = 0;i<n-1;i++) { if(a[i]>a[i+1]) { ans++; a[i+1]=a[i]; } } out.println(ans); } out.close(); } /* * public static long bincoef(int n, int k) { if(n < k) return 0L; return (p[n] * * pow((p[n - k] * p[k]) % mod, mod - 2,mod))%mod; } */ static long pow(long a, long b, long mod) { if (b == 0) { return 1L; } long val = pow(a, b / 2, mod); if (b % 2 == 0) { return val * val % mod; } return val * val % mod * a % mod; } static int gcd(int a, int b) { if (b == 0) { return a; } return gcd(b, a % b); } static int lcm(int a, int b) { return a * b / gcd(a, b); } static Kattio sc = new Kattio(); static PrintWriter out = new PrintWriter(System.out); static class Kattio { static BufferedReader r; static StringTokenizer st; public Kattio() { r = new BufferedReader(new InputStreamReader(System.in)); } public String next() { try { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(r.readLine()); } return st.nextToken(); } catch (Exception e) { return null; } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } } }
2031A
wrong_submission
medium
291,641,317
Java 21
WRONG_ANSWER on test 2
import java.util.*; public class monument { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t=sc.nextInt(); while(t>0) { int n=sc.nextInt(); int A[]=new int[n]; for(int i=0;i<n;i++) { A[i]=sc.nextInt(); } Arrays.sort(A); int count=0; for(int i=0;i<n-1;i++) { if(A[i]<A[i+1]) count++; } System.out.println(count); t--; } } }
2031A
wrong_submission
medium
292,446,597
C++20 (GCC 13-64)
WRONG_ANSWER on test 2
#include<bits/stdc++.h> using namespace std; const int N=5e5; int n,a[N]; void solve(){ cin>>n; map<int,int> mp; for(int i=1;i<=n;i++){ cin>>a[i]; mp[a[i]]=1; } cout<<mp.size()-1<<'\n'; } signed main(){ ios::sync_with_stdio(false); cin.tie(0); int t=1; cin>>t; while(t--){ solve(); } return 0; }
2031A
wrong_submission
hard
291,592,780
C++23 (GCC 14-64, msys2)
WRONG_ANSWER on test 2
#include<bits/stdc++.h> using namespace std; #define int long long const int N = 3e5+9; int a[N], b[N]; void haha() { int n;cin >> n;int cnt =0; if(n == 1) cnt = 0; else if(n == 2) { if(a[1] > a[2]) cnt = 1; } else if(n >= 3) { for(int i = 1; i <= n; i++) { cin >> a[i]; b[i] = a[i]; } sort(b+1, b+n+1); int x = b[(n+1)/2]; //cout << x << "\n"; for(int i = 1; i <= n/2; i++) if(a[i] > x) cnt ++; for(int i = n/2+1; i <= n; i++) if(a[i] < x) cnt ++; } cout << cnt << "\n"; return ; } signed main() { ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int t; cin >> t; while(t--) haha(); return 0; }
2031A
wrong_submission
hard
291,589,053
PyPy 3-64
WRONG_ANSWER on test 2
t = int(input()) for i in range(t): h = int(input()) k = list(map(int,input().split())) print(k[0]-k[-1])
2031A
wrong_submission
hard
291,618,569
Python 3
WRONG_ANSWER on test 2
t=int(input()) for _ in range(t): n=int(input()) h=list(map(int,input().split(" "))) le=len(h) mle=le*-1 if len(h)==1: print(0) continue else: c=0 for i in range(n-1): if h[i]>h[i+1]: c+=1 h[i],h[i+1]=h[i+1],h[i] else: continue print(c)
2031A
wrong_submission
hard
291,666,348
Java 8
WRONG_ANSWER on test 2
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-- !=0){ int n=sc.nextInt(); int[] arr=new int[n]; int min=Integer.MAX_VALUE; int max=Integer.MIN_VALUE; int count=0; for(int i=0;i<n;i++){ arr[i]=sc.nextInt(); min=Math.min(min,arr[i]); max=Math.max(max,arr[i]); } int mid=n/2; for(int i=0;i<n/2;i++){ if(arr[i]>arr[i+1]){ arr[i]=min; count++; if(i==n/2){ break; } } } for(int i=(n/2)+1;i<n;i++){if(arr[i]<arr[i-1]){ arr[i]=max; count++; if(i==n-1){ break; } } } if(n==1){ System.out.println("0"); } else{ System.out.println(count); } } } }
2031A
wrong_submission
hard
291,605,472
Java 21
WRONG_ANSWER on test 2
import java.util.*; public class Main { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); int a[]=new int[n]; for(int i=0;i<n;i++) { a[i]=sc.nextInt(); } if(n==1) { System.out.println(0); } else { int c=0; for(int i=0;i<n-1;i++) { if(a[i]>a[i+1]) { c++; } } System.out.println(c); } } } }
2031A
wrong_submission
hard
276,166,302
C++20 (GCC 13-64)
OK
#include <bits/stdc++.h> using u32 = unsigned; using i64 = long long; using u64 = unsigned long long; constexpr int inf = 1E9; void solve() { int n, m; std::cin >> n >> m; int t0, t1, t2; std::cin >> t0 >> t1 >> t2; std::vector<std::vector<std::array<int, 3>>> adj(n); for (int i = 0; i < m; i++) { int u, v, l1, l2; std::cin >> u >> v >> l1 >> l2; u--; v--; adj[u].push_back({v, l1, l2}); adj[v].push_back({u, l1, l2}); } std::vector<int> dp(n, -1); std::priority_queue<std::pair<int, int>> pq; pq.emplace(t0, n - 1); while (!pq.empty()) { auto [t, x] = pq.top(); pq.pop(); if (dp[x] != -1) { continue; } dp[x] = t; for (auto [y, l1, l2] : adj[x]) { int nt = -1; nt = std::max(nt, std::min(t, t1) - l1); if (t - l1 >= t2) { nt = std::max(nt, t - l1); } nt = std::max(nt, t - l2); if (nt >= 0) { pq.emplace(nt, y); } } } std::cout << dp[0] << "\n"; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int t; std::cin >> t; while (t--) { solve(); } return 0; }
2000G
right_submission
none
276,159,138
C++20 (GCC 13-64)
OK
/** * author: tourist * created: 13.08.2024 07:59:57 **/ #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "algo/debug.h" #else #define debug(...) 42 #endif int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int tt; cin >> tt; while (tt--) { int n, m; cin >> n >> m; int t1, t2, t0; cin >> t0 >> t1 >> t2; vector<vector<array<int, 3>>> g(n); for (int i = 0; i < m; i++) { int a, b, c, d; cin >> a >> b >> c >> d; --a; --b; g[a].push_back({b, c, d}); g[b].push_back({a, c, d}); } vector<int> dist(n, -1); dist[n - 1] = t0; priority_queue<pair<int, int>> s; s.emplace(dist[n - 1], n - 1); auto Put = [&](int v, int d) { if (d > dist[v]) { dist[v] = d; s.emplace(dist[v], v); } }; while (!s.empty()) { auto [expected, i] = s.top(); s.pop(); if (expected != dist[i]) { continue; } for (auto& [to, c, d] : g[i]) { Put(to, dist[i] - d); if (dist[i] <= t1 || dist[i] - c >= t2) { Put(to, dist[i] - c); } else { Put(to, t1 - c); } } } cout << dist[0] << '\n'; } return 0; }
2000G
right_submission
none
289,341,417
C++17 (GCC 7-32)
OK
// headers #include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <fstream> #include <functional> #include <iostream> #include <limits> #include <queue> #include <sstream> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #define ll long long const int MAXN = 100001; int t, n, m, t0, t1, t2, cnt; int head[MAXN], next[MAXN << 1], to[MAXN << 1], bustime[MAXN << 1], walktime[MAXN << 1]; void clear() { cnt = 0; std::memset(head, 0, sizeof(head)); std::memset(next, 0, sizeof(next)); std::memset(to, 0, sizeof(to)); std::memset(bustime, 0, sizeof(bustime)); std::memset(walktime, 0, sizeof(walktime)); } void addEdge(int u, int v, int l1, int l2) { cnt += 1; next[cnt] = head[u]; to[cnt] = v; bustime[cnt] = l1; walktime[cnt] = l2; head[u] = cnt; } struct Node { int intersection; int latest_time; bool operator()(const Node &a, const Node &b) { return a.latest_time < b.latest_time; } }; void solve() { std::scanf("%d%d%d%d%d", &n, &m, &t0, &t1, &t2); int u, v, l1, l2; for (int i = 0; i < m; i++) { std::scanf("%d%d%d%d", &u, &v, &l1, &l2); addEdge(u, v, l1, l2); addEdge(v, u, l1, l2); } std::priority_queue<Node, std::vector<Node>, Node> queue; queue.push((Node){n, t0}); std::unordered_map<int, int> latest; std::unordered_set<int> visited; while (!queue.empty()) { Node node = queue.top(); queue.pop(); if (visited.find(node.intersection) != visited.end()) { continue; } visited.insert(node.intersection); if (node.latest_time < 0) { std::printf("-1\n"); return; } if (node.intersection == 1) { std::printf("%d\n", node.latest_time); return; } for (int e = head[node.intersection]; e != 0; e = next[e]) { int next = to[e]; // try take bus int next_latest_time = node.latest_time - bustime[e]; if (node.latest_time > t1 && next_latest_time < t2) { // take bus ealier, arrive at current node at t1, // or walk and arrive at node.latest_time next_latest_time = std::max(t1 - bustime[e], node.latest_time - walktime[e]); } if (next_latest_time < 0) { continue; } if (latest.find(next) == latest.end() || latest[next] < next_latest_time) { latest[next] = next_latest_time; queue.push((Node){next, next_latest_time}); } } } std::printf("-1\n"); } int main() { std::scanf("%d", &t); for (int i = 0; i < t; i++) { clear(); solve(); } }
2000G
right_submission
none
276,356,347
C++17 (GCC 7-32)
WRONG_ANSWER on test 2
# include <bits/stdc++.h> using namespace std; # define int long long vector<tuple<int,int,int>> g[100005]; int t0, t1, t2; int n, m; bool ok(int time, int start, int goal){ priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> q; int dis[n+1]; memset(dis, 0x3f, sizeof(dis)); dis[start] = time; q.push({time, start}); // cout << endl; while(!q.empty()){ auto [curT, u] = q.top(); q.pop(); // cout << " :: " << curT << " " << u << endl; if(u == goal && curT <= t0) return true; if(t1 <= curT && curT < t2){ dis[u] = t2; q.push({t2, u}); } for(auto [v, tbus, twalk]: g[u]){ // walk if(curT+twalk < dis[v]){ dis[v] = curT + twalk; q.push({dis[v], v}); } // bus if(curT < t1 && t1 < curT+tbus) continue; // cannot board the bus due to phone call when arrive if(t1 <= curT && curT < t2) continue; // cannot board the bus because still on call if(curT+tbus < dis[v]){ dis[v] = curT + tbus; q.push({dis[v], v}); } } } return false; } int solve(){ cin >> n >> m; for(int i=1; i<=n; i++) g[i].clear(); cin >> t0 >> t1 >> t2; while(m--){ int u, v, tbus, twalk; cin >> u >> v >> tbus >> twalk; g[u].push_back({v, tbus, twalk}); g[v].push_back({u, tbus, twalk}); } int lo = 0, hi = t0, ans = -1; while(lo <= hi){ int mid = (lo + hi) / 2; if(ok(mid, 1, n)){ ans = mid; lo = mid+1; } else hi = mid-1; } cout << ans << endl; return 0; } signed main(){ ios_base::sync_with_stdio(false); int t; cin >> t; for(int tc=1; tc<=t; tc++){ int ans = solve(); } } /* */
2000G
wrong_submission
easy
293,740,538
C++20 (GCC 13-64)
WRONG_ANSWER on test 2
#include <bits/stdc++.h> using namespace std; long long inf = numeric_limits<long long>::max(); int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); long long t; cin>>t; vector<int> ans(t); int count = 0; while (t--){ count++; long long n,m; cin>>n>>m; if (count==461){ cout<<n<<" "<<m<<endl; } long long t0,t1,t2; cin>>t0>>t1>>t2; if (count==461){ cout<<t0<<" "<<t1<<" "<<t2<<endl; } long long temp = t2; t2 = t0-t1; t1 = t0-temp; vector<vector<vector<long long>>> adj_list(n+1); for (long long i=0;i<m;i++){ long long u,v,l1,l2; cin>>u>>v>>l1>>l2; if (count==461){ cout<<u<<" "<<v<<" "<<l1<<" "<<l2<<endl; } adj_list[u].push_back({v,l1,l2}); adj_list[v].push_back({u,l1,l2}); } priority_queue<pair<long long,long long>> pq; pq.push({0,n}); vector<long long> dist(adj_list.size(),inf); dist[n] = 0; while (!pq.empty()){ long long curr_time = pq.top().first; long long curr = pq.top().second; pq.pop(); if (dist[curr]<curr_time){ continue; } for (vector<long long> child:adj_list[curr]){ if ((curr_time + child[1] <= t1 || t2<=curr_time) && (curr_time<= t1 || t2<=curr_time)){ if (dist[child[0]] > dist[curr]+child[1]){ dist[child[0]] = dist[curr]+child[1]; pq.push({dist[child[0]],child[0]}); } } if (curr_time<=t1 && dist[child[0]] > t2+child[1]){ dist[child[0]] = t2+child[1]; pq.push({dist[child[0]],child[0]}); } if (dist[child[0]] > dist[curr]+child[2]){ dist[child[0]] = dist[curr]+child[2]; pq.push({dist[child[0]],child[0]}); } } } ans[count-1] = max(t0-dist[1],-1LL); } for (int x:ans){ cout<<x<<"\n"; } return 0; }
2000G
wrong_submission
easy
288,448,359
C++20 (GCC 13-64)
WRONG_ANSWER on test 2
#include<bits/stdc++.h> #define int long long using namespace std; const int N = 1e5 + 5; struct edge { int v; int w1; int w2; int nxt; } e[N << 1]; int head[N], ind; int vis[N]; struct node { int v; int t; bool operator<(const node &a) const { return t < a.t; } }; void add(int u, int v, int w1, int w2) { e[ind].v = v; e[ind].w1 = w1; e[ind].w2 = w2; e[ind].nxt = head[u]; head[u] = ind++; } void solve() { int n, m; cin >> n >> m; ind = 0; for (int i = 0; i <= n; i++) head[i] = -1; int t, t1, t2; cin >> t >> t1 >> t2; for (int i = 1; i <= m; i++) { int u, v, w1, w2; cin >> u >> v >> w1 >> w2; add(u, v, w1, w2); add(v, u, w1, w2); } vector<node> ans; vector<node> ans1;//纯等 int res = -1; priority_queue<node> q;//先坐车 q.push({n, t}); for (int i = 0; i <= n; i++) vis[i] = 0; while (!q.empty()) { auto [u, tt] = q.top(); q.pop(); if (u == 1) { res = max(res, tt); continue; } if (vis[u] == 1) continue; vis[u] = 1; for (int i = head[u]; ~i; i = e[i].nxt) { int v = e[i].v; int w = e[i].w1; if (vis[v] == 1) continue; if (tt - w >= t2) { q.push({v, tt - w}); } else { ans.push_back({u, tt}); ans1.push_back({u, t1}); } } } for (auto i: ans) q.push(i); while (!q.empty()) { auto [u, tt] = q.top(); q.pop(); if (u == 1) { res = max(res, tt); continue; } if (vis[u] == 2) continue; vis[u] = 2; for (int i = head[u]; ~i; i = e[i].nxt) { int v = e[i].v; int w = e[i].w2; if (vis[v] == 2) continue; if (tt <= t1) { ans1.push_back({u, tt}); } else { if (tt >= w) { q.push({v, tt - w}); } else { ans1.push_back({u, t1}); } } } } for (auto i: ans1) q.push(i); while (!q.empty()) { auto [u, tt] = q.top(); q.pop(); if (u == 1) { res = max(res, tt); continue; } if (vis[u] == 3) continue; vis[u] = 3; for (int i = head[u]; ~i; i = e[i].nxt) { int v = e[i].v; int w = e[i].w1; if (vis[v] == 3) continue; if (tt - w < 0) continue; q.push({v, tt - w}); } } cout << res << "\n"; } signed main() { #ifdef ONLINE_JUDGE #else freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif ios::sync_with_stdio(false); cout.tie(nullptr); int t = 1; cin >> t; while (t--) { solve(); } }
2000G
wrong_submission
easy
276,338,442
PyPy 3-64
WRONG_ANSWER on test 2
# https://codeforces.com/contest/2000 import sys from heapq import heappush, heappop input = lambda: sys.stdin.readline().rstrip() # faster! INF = 10 ** 18 def dijkstra(n, adj, start, finish, t_start, walk_call, t1, t2): dist = [INF] * n dist[start] = t_start queue = [] heappush(queue, (dist[start], start)) while queue: d, v = heappop(queue) if d == dist[v]: for u, l1, l2 in adj[v]: if d >= t2 or d + l1 <= t1: if d + l1 < dist[u]: dist[u] = d + l1 heappush(queue, (dist[u], u)) elif walk_call: if d + l2 < dist[u]: dist[u] = d + l2 heappush(queue, (dist[u], u)) else: if t2 + l1 < dist[u]: dist[u] = t2 + l1 heappush(queue, (dist[u], u)) return dist[finish] def solve_case(t): n, m = map(int, input().split()) # 2 <= n <= 10**5, 1 <= m <= 10**5 t0, t1, t2 = map(int, input().split()) # t1 < t2 < t0 adj = [[] for _ in range(n)] for _ in range(m): u, v, l1, l2 = map(int, input().split()) u -= 1 v -= 1 adj[u] += [(v, l1, l2)] adj[v] += [(u, l1, l2)] if t==24: return f"{str(adj[2:4]).replace(', ','_')}" start = 0 finish = n - 1 x = dijkstra(n, adj, start, finish, 0, True, t1, t2) y = dijkstra(n, adj, start, finish, 0, False, t1, t2) if min(x, y) > t0: return -1 lo, hi = 0, t0 while lo + 1 < hi: mid = (lo + hi) // 2 x = dijkstra(n, adj, start, finish, mid, True, t1, t2) y = dijkstra(n, adj, start, finish, mid, False, t1, t2) xy = min(x, y) if xy <= t0: lo = mid else: hi = mid return lo ans = [] for t in range(int(input())): ans += [str(solve_case(t))] print("\n".join(ans))
2000G
wrong_submission
easy
276,305,567
PyPy 3-64
WRONG_ANSWER on test 2
import heapq import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def make_graph(n, m): l = 2 * m + n x, y, s = [0] * (2 * l), [0] * (2 * l), [0] * (((n + 1) << 1) + 3) for i in range(0, m << 2, 4): u, v, l1, l2 = map(int, input().split()) for k in range(2): s[g(u, k) + 2] += 1 s[g(v, k) + 2] += 1 x[i ^ 0], x[i ^ 1], x[i ^ 2], x[i ^ 3] = g(u, 0), g(v, 0), g(u, 1), g(v, 1) y[i ^ 0], y[i ^ 1], y[i ^ 2], y[i ^ 3] = l1, l1, l2, l2 k = m << 2 for i in range(1, n + 1): for j in range(2): s[g(i, j) + 2] += 1 x[k ^ j] = g(i, j ^ 1) k += 2 for i in range(3, ((n + 1) << 1) + 3): s[i] += s[i - 1] G, W = [0] * (2 * l), [0] * (2 * l) for i in range(2 * l): j = x[i] + 1 G[s[j]] = x[i ^ 1] W[s[j]] = y[i ^ 1] s[j] += 1 return G, W, s def f(u, v): return u << 20 ^ v def g(u, v): return u << 1 ^ v def dijkstra(s): dist = [-1] * (((n + 1) << 1) + 1) dist[s] = t0 visit = [0] * (((n + 1) << 1) + 1) p = [f(inf - t0, s)] while p: d, u = inf - (p[0] >> 20), heapq.heappop(p) & 0xfffff if dist[u] < d: continue if d <= t1: x = 0 elif t1 < d < t2: x = 1 else: x = 2 visit[u] = 1 for i in range(s0[u], s0[u + 1]): v, nd = G[i], dist[u] - W[i] if nd <= t1: y = 0 elif t1 < nd < t2: y = 1 else: y = 2 if not u & 1 and not v & 1 and x ^ y: nd = t1 - W[i] if not visit[v] and nd > dist[v]: dist[v] = nd heapq.heappush(p, f(inf - dist[v], v)) return dist t = int(input()) ans = [] inf = pow(10, 9) + 1 for _ in range(t): n, m = map(int, input().split()) t0, t1, t2 = map(int, input().split()) G, W, s0 = make_graph(n, m) dist = dijkstra(g(n, 0)) ans0 = dist[2] ans.append(ans0) sys.stdout.write("\n".join(map(str, ans)))
2000G
wrong_submission
easy
276,291,364
PyPy 3-64
WRONG_ANSWER on test 2
I = lambda : list(map(int, input().split(' '))) R = lambda : (int(input())) import math from collections import defaultdict from collections import deque from heapq import heappop, heappush, heapify def is_possible(node, e, t0, t1, t2): dis = [float('inf') for i in range(n + 1)] dis[1] = node[0][0] heapify(node) ind = 0 while ind < len(node) : # d, curr, parent = heappop(node) d, curr, parent = node[ind] dis[curr] = min(dis[curr], d) for v, l1, l2 in e[curr]: if d <= t1: time_req = (d + l1) if (d + l1 <= t1) else (d + l2) if time_req > t2 + l1: time_req = t2 + l1 elif d > t1 and d < t2: time_req = d + l2 if time_req > t2 + l1: time_req = t2 + l1 elif d >= t2: time_req = d + l1 if v != n and v != parent: if dis[v] > time_req and dis[v] == float('inf'): # heappush(node, (time_req, v, curr)) node.append((time_req, v, curr)) dis[v] = min(time_req, dis[v]) elif v == n and v != parent: dis[v] = min(dis[v], time_req) ind += 1 return dis[n] <= t0 for kp in range(R()): n,m = I() t0, t1, t2 = I() e = [[] for i in range(n+1)] prev = -1 low = 0 high = t0 for i in range(m): u,v,l1,l2 = I() e[u].append((v,l1,l2)) e[v].append((u,l1,l2)) while low <= high: mid = (low + high)//2 is_d = is_possible( [(mid, 1, -1)] , e, t0, t1, t2) if is_d == True: prev = mid low = mid + 1 else: high = mid - 1 # print(high, low, mid, is_d) print(prev)
2000G
wrong_submission
easy
276,845,167
Java 21
WRONG_ANSWER on test 2
//package Codeforces; import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.LinkedList; import java.util.StringTokenizer; import java.util.TreeSet; import java.util.*; public class CallDuringTheJourney { final static Scanner sc = new Scanner(System.in); public static void main(String[] args) { new Thread(null, null, "Thread", 1 << 27) { public void run() { try { s = new FastReader(); out = new PrintWriter(new BufferedOutputStream(System.out)); solve(); out.close(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } }.start(); } static void solve() throws Exception { int testcases = sc.nextInt(); for (int test = 0; test<testcases; ++test) { int n = sc.nextInt(); int m = sc.nextInt(); Graph g = new Graph(n, m); int t0 = sc.nextInt(); int t1 = sc.nextInt(); int t2 = sc.nextInt(); for(int i=0; i<m; ++i){ int u = sc.nextInt(); int v = sc.nextInt(); int bussTime = sc.nextInt(); int walkTime = sc.nextInt(); g.createEdge(u, v, bussTime, walkTime); } int result = findTimeToReach(g, t0, t1, t2); out.println(result); } } private static int findTimeToReach(Graph g, int t0, int t1, int t2){ g.populateMaxTimeToReach(t0, t1, t2); return g.nodes.get(0).maxTimeTorReach; } private static boolean isOverlappingInterval(int busTime, int maxTimeTorReach, int t1, int t2) { return (t2 > busTime && t1 < maxTimeTorReach); } public static class Graph{ List<Node> nodes; // List<Edge> edges; Map<Node, List<Edge>> adjacencyList; static int edgeid = 0; int N; int M; Graph(int N, int M){ this.N = N; this.M = M; nodes = new ArrayList<>(this.N); // edges = new ArrayList<>(this.M); adjacencyList = new HashMap<>(); for(int i = 0; i < N; i++){ Node u = new Node(i); nodes.add(u); adjacencyList.put(u, new ArrayList<>()); } } void populateMaxTimeToReach(int t0, int t1, int t2){ PriorityQueue<Node> pq = new PriorityQueue<>((a, b) -> b.maxTimeTorReach - a.maxTimeTorReach); // out.println("Checking PQ"); // for(int i=1; i<N; i++){ // nodes.get(i).maxTimeTorReach = i; // pq.add(nodes.get(i)); // } // while(!pq.isEmpty()){ // out.println(pq.poll().maxTimeTorReach); // } // out.println("done"); nodes.get(N-1).maxTimeTorReach = t0; pq.add(nodes.get(N-1)); int walkTime, busTime, currentBestTime; Set<Integer> visited = new HashSet<>(); while(!pq.isEmpty()){ Node node = pq.poll(); pq.remove(node); if(visited.contains(node.id)){ continue;} visited.add(node.id); if(node.maxTimeTorReach < 0) break; if(node.id == 0) break; for(Edge edge: adjacencyList.get(node)){ Node neib = edge.u; if(edge.u.id == node.id){ neib = edge.v; } walkTime = node.maxTimeTorReach - edge.walkTime; busTime = node.maxTimeTorReach - edge.busTime; if(isOverlappingInterval(busTime, node.maxTimeTorReach, t1, t2)){ busTime = t1 - edge.busTime; } currentBestTime = Math.max(walkTime, busTime); if(neib.maxTimeTorReach < currentBestTime){ neib.maxTimeTorReach = currentBestTime; pq.add(neib); } } } } public static class Node{ int id; int maxTimeTorReach; Node(int id){ this.id = id; this.maxTimeTorReach = -1; } } public static class Edge{ int id; Node u; Node v; int walkTime; int busTime; public Edge(Node u, Node v, int walkTime, int busTime) { this.u = u; this.v = v; this.walkTime = walkTime; this.busTime = busTime; this.id = edgeid; edgeid++; } } void createEdge(int u, int v, int busTime, int walkTime){ --u; --v; Node uNode = nodes.get(u); Node vNode = nodes.get(v); Edge edge = new Edge(uNode, vNode, walkTime, busTime); adjacencyList.get(uNode).add(edge); adjacencyList.get(vNode).add(edge); } } public static FastReader s; public static PrintWriter out; public static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } double nextDouble() { return Double.parseDouble(next()); } long nextLong() { return Long.parseLong(next()); } int[] nextIntArray(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = nextInt(); } return arr; } long[] nextLongArray(int n) { long[] arr = new long[n]; for (int i = 0; i < n; i++) { arr[i] = nextLong(); } return arr; } String nextLine() { String str = ""; try { str = br.readLine(); } catch (Exception e) { e.printStackTrace(); } return str; } } }
2000G
wrong_submission
easy
276,843,516
Java 21
WRONG_ANSWER on test 2
//package Codeforces; import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.LinkedList; import java.util.StringTokenizer; import java.util.TreeSet; import java.util.*; public class CallDuringTheJourney { final static Scanner sc = new Scanner(System.in); public static void main(String[] args) { new Thread(null, null, "Thread", 1 << 27) { public void run() { try { s = new FastReader(); out = new PrintWriter(new BufferedOutputStream(System.out)); solve(); out.close(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } }.start(); } static void solve() throws Exception { int testcases = sc.nextInt(); for (int test = 0; test<testcases; ++test) { int n = sc.nextInt(); int m = sc.nextInt(); Graph g = new Graph(n, m); int t0 = sc.nextInt(); int t1 = sc.nextInt(); int t2 = sc.nextInt(); for(int i=0; i<m; ++i){ int u = sc.nextInt(); int v = sc.nextInt(); int bussTime = sc.nextInt(); int walkTime = sc.nextInt(); g.createEdge(u, v, bussTime, walkTime); } int result = findTimeToReach(g, t0, t1, t2); out.println(result); } } private static int findTimeToReach(Graph g, int t0, int t1, int t2){ g.populateMaxTimeToReach(t0, t1, t2); return g.nodes.get(0).maxTimeTorReach; } private static boolean isOverlappingInterval(int busTime, int maxTimeTorReach, int t1, int t2) { return (t2 > busTime && t1 < maxTimeTorReach); } public static class Graph{ List<Node> nodes; // List<Edge> edges; Map<Node, List<Edge>> adjacencyList; static int edgeid = 0; int N; int M; Graph(int N, int M){ this.N = N; this.M = M; nodes = new ArrayList<>(this.N); // edges = new ArrayList<>(this.M); adjacencyList = new HashMap<>(); for(int i = 0; i < N; i++){ Node u = new Node(i); nodes.add(u); adjacencyList.put(u, new ArrayList<>()); } } void populateMaxTimeToReach(int t0, int t1, int t2){ nodes.get(N-1).maxTimeTorReach = t0; PriorityQueue<Node> pq = new PriorityQueue<>(); pq.add(nodes.get(N-1)); int walkTime, busTime, currentBestTime; while(!pq.isEmpty()){ Node node = pq.poll(); if(node.maxTimeTorReach < 0 || node.id == 0) break; for(Edge edge: adjacencyList.get(node)){ Node neib = edge.u; if(edge.u.id == node.id){ neib = edge.v; } walkTime = node.maxTimeTorReach - edge.walkTime; busTime = node.maxTimeTorReach - edge.busTime; if(isOverlappingInterval(busTime, node.maxTimeTorReach, t1, t2)){ busTime = t1 - edge.busTime; } currentBestTime = Math.max(walkTime, busTime); if(neib.maxTimeTorReach < currentBestTime){ neib.maxTimeTorReach = currentBestTime; pq.add(neib); } } } } public static class Node implements Comparable<Node>{ int id; int maxTimeTorReach; Node(int id){ this.id = id; this.maxTimeTorReach = -1; } @Override public int compareTo(Node o) { return o.maxTimeTorReach - this.maxTimeTorReach ; } } public static class Edge{ int id; Node u; Node v; int walkTime; int busTime; public Edge(Node u, Node v, int walkTime, int busTime) { this.u = u; this.v = v; this.walkTime = walkTime; this.busTime = busTime; this.id = edgeid; edgeid++; } } void createEdge(int u, int v, int busTime, int walkTime){ --u; --v; Node uNode = nodes.get(u); Node vNode = nodes.get(v); Edge edge = new Edge(uNode, vNode, walkTime, busTime); adjacencyList.get(uNode).add(edge); adjacencyList.get(vNode).add(edge); } } public static FastReader s; public static PrintWriter out; public static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } double nextDouble() { return Double.parseDouble(next()); } long nextLong() { return Long.parseLong(next()); } int[] nextIntArray(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = nextInt(); } return arr; } long[] nextLongArray(int n) { long[] arr = new long[n]; for (int i = 0; i < n; i++) { arr[i] = nextLong(); } return arr; } String nextLine() { String str = ""; try { str = br.readLine(); } catch (Exception e) { e.printStackTrace(); } return str; } } }
2000G
wrong_submission
easy
276,274,261
C++14 (GCC 6-32)
WRONG_ANSWER on test 8
#include <iostream> #include <stdio.h> #include <vector> #include <queue> using namespace std; const int maxn = 1e5 + 5, ninf = 0x80000000; int T, n, m, t0, t1, t2, et[maxn]; struct Edge{ int to, l1, l2; Edge(int to, int l1, int l2){ this->to = to; this->l1 = l1; this->l2 = l2; } }; struct Node{ int idx, t; inline bool operator < (const Node &other) const{ return t < other.t; } Node(int idx, int t){ this->idx = idx; this->t = t; } }; vector<Edge> to[maxn]; inline void clear_vec(vector<Edge> &vec){ vector<Edge> empty; swap(empty, vec); } inline void solve(){ cin >> n >> m; cin >> t0 >> t1 >> t2; for(int i = 1; i <= n; ++i) clear_vec(to[i]); for(int i = 1; i <= n; ++i) et[i] = ninf; for(int i = 0; i < m; ++i){ int u, v, l1, l2; cin >> u >> v >> l1 >> l2; to[u].push_back(Edge(v, l1, l2)); to[v].push_back(Edge(u, l1, l2)); } priority_queue<Node> pq; pq.push(Node(n, t0)); int rt; while(!pq.empty()){ Node top = pq.top(); pq.pop(); // cerr << "VIS: " << top.idx << ' ' << top.t << endl; rt = top.t; // cerr << et[top.idx] << endl; if(et[top.idx] != ninf) continue; et[top.idx] = rt; for(auto e: to[top.idx]) if(et[e.to] == ninf){ if(rt <= t1 || rt - e.l1 >= t2) pq.push(Node(e.to, rt - e.l1)); else pq.push(Node(e.to, max(rt - e.l2, t1 - e.l1))); } } // for(int i = 1; i <= n; ++i) // cerr << et[i] << " "; // cerr << endl; cout << max(-1, et[1]) << endl; } int main(){ cin.tie(0)->sync_with_stdio(false); cin >> T; while(T--) solve(); return 0; }
2000G
wrong_submission
medium
277,476,713
Java 21
TIME_LIMIT_EXCEEDED on test 8
import java.io.*; import java.util.*; public class Main { public static int INF = 0x3f3f3f3f, mod = 1000000007, mod9 = 998244353; public static void main(String args[]){ try { PrintWriter o = new PrintWriter(System.out); boolean multiTest = true; // init if(multiTest) { int t = nextInt(), loop = 0; while (loop < t) {loop++;solve(o);} } else solve(o); o.close(); } catch (Exception e) {e.printStackTrace();} } static List<int[]>[] G; static int n, m; static int[] t; static void solve(PrintWriter o) { try { n = nextInt(); m = nextInt(); t = new int[3]; for(int i=0;i<3;i++) t[i] = nextInt(); G = new ArrayList[n]; Arrays.setAll(G, key->new ArrayList<>()); for(int i=0;i<m;i++) { int u = nextInt(), v = nextInt(); u--;v--; int l1 = nextInt(), l2 = nextInt(); G[u].add(new int[]{v, l1, l2}); G[v].add(new int[]{u, l1, l2}); } int l = 0, r = t[0]+1; while(l < r) { int mi = (l+r)>>1; if(check(mi)) l = mi+1; else r = mi; } if(l == 0) { o.println(-1); return; } o.println(l-1); } catch (Exception e) { e.printStackTrace(); } } static boolean check(int m) { int[] dist = new int[n]; Arrays.fill(dist, Integer.MAX_VALUE); dist[0] = m; PriorityQueue<int[]> queue = new PriorityQueue<>((x,y)->Integer.compare(x[1], y[1])); queue.offer(new int[]{0, m}); while(!queue.isEmpty()) { int[] it = queue.poll(); int u = it[0], now = it[1]; if(now > dist[u]) continue; if(u == n-1) { return true; } for(int[] it1: G[u]) { int v = it1[0], w1 = it1[1], w2 = it1[2]; boolean used = false; if(now+w1 <= t[0]) { if((now < t[1] && now+w1 <= t[1] || now >= t[2]) && now+w1 < dist[v]) { dist[v] = now+w1; queue.offer(new int[]{v, now+w1}); used = true; } } if(!used) { int comp1 = Integer.MAX_VALUE, comp2 = Integer.MAX_VALUE; if(now < t[2] && t[2]+w1 <= t[0] && t[2]+w1 < dist[v]) comp1 = t[2]+w1; if(now+w2 <= t[0] && now+w2 < dist[v]) comp2 = now+w2; comp1 = Math.min(comp1, comp2); if(comp1 < dist[v]) queue.offer(new int[]{v, comp1}); } } } return false; } public static int upper_bound(int[] a, int val){ int l = 0, r = a.length; while(l < r){ int mid = l + (r - l) / 2; if(a[mid] <= val) l = mid + 1; else r = mid; } return l; } public static int lower_bound(int[] a, int val){ int l = 0, r = a.length; while(l < r){ int mid = l + (r - l) / 2; if(a[mid] < val) l = mid + 1; else r = mid; } return l; } public static long gcd(long a, long b) { return b == 0 ? a : gcd(b, a%b); } public static long[] extgcd(long a, long b) { if(b == 0) return new long[]{1, 0}; long[] it = extgcd(b, a%b); long x = it[1], y = it[0]; y -= a/b*x; return new long[]{x, y}; } public static long lcm(long a, long b){ return a / gcd(a,b)*b; } public static long qpow(long a, long n, int md){ a %= md; long ret = 1l; while(n > 0){ if((n & 1) == 1) ret = ret * a % md; n >>= 1; a = a * a % md; } return ret; } public static class FenWick { int n; long[] a; long[] tree; public FenWick(int n){ this.n = n; a = new long[n+1]; tree = new long[n+1]; } private void add(int x, long val){ while(x <= n){ tree[x] += val; x += x&-x; } } private void addMx(int x, long val) { a[x] += val; tree[x] = a[x]; while(x <= n) { for(int i=1;i<(x&-x);i<<=1) tree[x] = Math.max(tree[x], tree[x-i]); x += x&-x; } } private long query(int x){ long ret = 0l; while(x > 0){ ret += tree[x]; x -= x&-x; } return ret; } private long queryMx(int l, int r) { long res = 0l; while(l <= r) { if(r-(r&-r) >= l) { res = Math.max(res, tree[r]); r -= r&-r; } else { res = Math.max(res, a[r]); r--; } } return res; } } static class DSU { int[] parent; public DSU(int n) { parent = new int[n]; for(int i=0;i<n;i++) parent[i] = i; } public int find(int x) { if(parent[x] != x) parent[x] = find(parent[x]); return parent[x]; } public void union(int x, int y) { int root_x = find(x); int root_y = find(y); if(root_x == root_y) return; parent[root_x] = root_y; } } private static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); private static StringTokenizer tokenizer = new StringTokenizer(""); private static String next() throws IOException{ while(!tokenizer.hasMoreTokens()){tokenizer = new StringTokenizer(reader.readLine());} return tokenizer.nextToken(); } public static int nextInt() throws IOException {return Integer.parseInt(next());} public static Long nextLong() throws IOException {return Long.parseLong(next());} public static double nextDouble() throws IOException {return Double.parseDouble(next());} public static char nextChar() throws IOException {return next().toCharArray()[0];} public static String nextString() throws IOException {return next();} public static String nextLine() throws IOException {return reader.readLine();} }
2000G
wrong_submission
medium
277,104,325
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 9
import math from collections import Counter import sys import heapq input = sys.stdin.readline t = int(input()) for _ in range(t): n, m = map(int, input().split()) eventTime, startCall, endCall = map(int, input().split()) neighbourNodes = [[] for i in range(n)] for i in range(m): path, toPath, durationBus, durationWalk = map(int, input().split()) path -= 1 toPath -= 1 neighbourNodes[path].append([toPath, durationBus, durationWalk]) neighbourNodes[toPath].append([path, durationBus, durationWalk]) def solve(): leftPointer, rightPointer = 0, eventTime ans = float('inf') def isValid(startTime): heap = [[startTime, 0]] arrivalTime = [[float('inf'), float('inf')] for i in range(n)] arrivalTime[0][1 if startTime >= endCall else 0] = startTime while heap: currTime, currNode = heapq.heappop(heap) for node, durationBus, durationWalk in neighbourNodes[currNode]: if currTime + durationWalk <= startCall or currTime >= endCall: endTime = currTime + durationBus newState = 1 if endTime >= endCall else 0 if arrivalTime[node][newState] > endTime: arrivalTime[node][newState] = endTime heapq.heappush(heap, [endTime, node]) continue if endCall >= currTime >= startCall or currTime + durationBus > startCall: for endTime in [currTime + durationWalk, endCall + durationBus]: newState = 1 if endTime >= endCall else 0 if arrivalTime[node][newState] > endTime: arrivalTime[node][newState] = endTime heapq.heappush(heap, [endTime, node]) continue for endTime in [currTime + durationBus, currTime + durationWalk, endCall + durationBus]: newState = 1 if endTime >= endCall else 0 if endTime <= currTime: continue if arrivalTime[node][newState] > endTime: arrivalTime[node][newState] = endTime heapq.heappush(heap, [endTime, node]) return arrivalTime[n - 1][1] <= eventTime or arrivalTime[n - 1][0] <= endCall while rightPointer >= leftPointer: middlePointer = (leftPointer + rightPointer) // 2 if isValid(middlePointer): ans = middlePointer leftPointer = middlePointer + 1 else: rightPointer = middlePointer - 1 return ans if ans != float('inf') else -1 print(solve())
2000G
wrong_submission
medium
276,326,449
Python 3
TIME_LIMIT_EXCEEDED on test 10
# Author : Omm Praksh Sahoo # Calm, Down... Wrong Submission Have 10 Mins Penalty import heapq I = lambda: input() II = lambda: int(input()) MII = lambda: map(int, input().split()) LI = lambda: list(input().split()) LII = lambda: list(map(int, input().split())) LGMII = lambda: map(lambda x: int(x) - 1, input().split()) LGLII = lambda: list(map(lambda x: int(x) - 1, input().split())) inf = float('inf') # ######################################################################################################### # #-----------------------------------------------Code----------------------------------------------------# # ######################################################################################################### # # import heapq def solve(): n, m = MII() t0, t1, t2 = MII() graph = [[] for _ in range(n)] for _ in range(m): u, v, l1, l2 = MII() u -= 1 v -= 1 graph[u].append((v, l1, l2)) graph[v].append((u, l1, l2)) def by_bus(t_start, t_end): return t_end <= t1 or t_start >= t2 def predicate(start_time): pq = [(start_time, 0)] dist = [inf] * n dist[0] = start_time while pq: current_time, u = heapq.heappop(pq) # Early exit if we reach the destination if u == n - 1 and current_time <= t0: return True if current_time > dist[u]: continue for v, l1, l2 in graph[u]: # Relax the edge with l1 new_time = current_time + l1 if by_bus(current_time, new_time) and dist[v] > new_time: dist[v] = new_time heapq.heappush(pq, (new_time, v)) # Relax the edge with adjusted time adjusted_time = max(current_time, t2) + l1 if dist[v] > adjusted_time: dist[v] = adjusted_time heapq.heappush(pq, (adjusted_time, v)) # Relax the edge with l2 new_time_with_l2 = current_time + l2 if dist[v] > new_time_with_l2: dist[v] = new_time_with_l2 heapq.heappush(pq, (new_time_with_l2, v)) return dist[n - 1] <= t0 lo, hi = 0, t0 ans = -1 while lo <= hi: mid = (lo + hi) // 2 if predicate(mid): ans = mid lo = mid + 1 else: hi = mid - 1 return ans t1 = II() for _ in range(t1): print(solve())
2000G
wrong_submission
medium
276,231,245
C++20 (GCC 13-64)
TIME_LIMIT_EXCEEDED on test 11
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #pragma GCC target ("avx2") #pragma GCC optimize ("Ofast") #pragma GCC optimize ("unroll-loops") #define f first #define s second #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) ((int) (x).size()) #define pb push_back #define mp make_pair #define int long long using namespace std; using namespace __gnu_pbds; template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template <typename T> inline bool umin(T &a, const T &b) { if(a > b) { a = b; return 1; } return 0; } template <typename T> inline bool umax(T &a, const T &b) { if(a < b) { a = b; return 1; } return 0; } typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const ll mod = 998244353; const ll base = 1e6 + 9; const ll inf = 1e18; const int MAX = 2e5 + 42; const int LG = 20; random_device rd; mt19937 gen(rd()); uniform_int_distribution<ll> dis(1, inf); void solve() { int n, m; cin >> n >> m; int x, y, z; cin >> z >> x >> y; vector<vector<array<int, 3>>> g(n + 1); while(m--) { int u, v, l, r; cin >> u >> v >> l >> r; g[u].pb({v, l, r}); g[v].pb({u, l, r}); } auto check = [&](int st) { auto dijkstra = [&](vector<pii> sources, bool flag) { vector<int> d(n + 1, inf); for(auto [v, dst] : sources) d[v] = dst; priority_queue<pii> q; for(int v = 1; v <= n; v++) q.push({d[v], v}); while(sz(q)) { auto [dst, v] = q.top(); q.pop(); if(d[v] != dst) continue; for(auto [to, a, b] : g[v]) { int w = (flag? b : a); if(d[to] > d[v] + w) { d[to] = d[v] + w; q.push({d[to], to}); } } } return d; }; vector<pii> sources = {mp(1, st)}; auto d1 = dijkstra(sources, 0); if(d1[n] <= x) return true; sources.clear(); for(int v = 1; v <= n; v++) { if(d1[v] <= x) sources.pb({v, d1[v]}); } if(sources.empty()) sources = {mp(1, st)}; auto d2 = dijkstra(sources, 1); if(d2[n] <= y) return true; for(int v = 1; v <= n; v++) umax(d2[v], y); sources.clear(); for(int v = 1; v <= n; v++) { sources.pb({v, d2[v]}); } auto d = dijkstra(sources, 0); // cout << st << ": " << d[n] << endl; return d[n] <= z; }; int l = 0, r = z; while(l <= r) { m = l + r >> 1; if(check(m)) l = m + 1; else r = m - 1; } cout << r << '\n'; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int ttt = 1; cin >> ttt; while(ttt--) { solve(); } }
2000G
wrong_submission
medium
288,835,419
Java 21
TIME_LIMIT_EXCEEDED on test 15
import java.util.*; public class Main{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=0;i<t;i++){ int n=sc.nextInt(),m=sc.nextInt(),t0=sc.nextInt(),t1=sc.nextInt(),t2=sc.nextInt(); List<int[]> path[]=new List[n+5]; for(int j=1;j<=n;j++){ path[j]=new ArrayList<>(); } for(int j=0;j<m;j++){ int u=sc.nextInt(),v=sc.nextInt(),l1=sc.nextInt(),l2=sc.nextInt(); path[u].add(new int[]{v,l1,l2}); path[v].add(new int[]{u,l1,l2}); } if(find(n,0,path,t1,t2)>t0){ System.out.println("-1"); } else{ int l=0,r=(int)1e9; while(l<r){ int mid=(l+r)>>1; if(find(n,mid,path,t1,t2)<=t0){ l=mid; } else{ r=mid-1; } if(l==r-1){ if(find(n,r,path,t1,t2)<=t0){ l=r; } break; } } System.out.println(l); } } } static long find(int n,int start,List<int[]> path[],int t1,int t2){ Queue<long[]> q=new PriorityQueue<>((a,b)->Long.compare(a[1],b[1])); long dis[]=new long[n+5]; Arrays.fill(dis,(long)1e18); dis[1]=start; q.add(new long[]{1,start}); while(!q.isEmpty()){ long a[]=q.poll(); if(dis[(int)a[0]]<a[1]){ continue; } for(int b[]:path[(int)a[0]]){ long d=a[1]+b[2]; if(dis[b[0]]>d){ q.add(new long[]{b[0],d}); dis[b[0]]=d; } d=a[1]+b[1]; if(!(d<=t1||a[1]>=t2)){ d=t2+b[1]; } if(dis[b[0]]>d){ q.add(new long[]{b[0],d}); dis[b[0]]=d; } } } return dis[n]; } }
2000G
wrong_submission
medium
277,286,268
C++14 (GCC 6-32)
TIME_LIMIT_EXCEEDED on test 17
#include<bits/stdc++.h> using namespace std; #define int long long #define ll long long #ifndef ONLINE_JUDGE #include "debug.h" #else #define deb(x...) #endif const int mod = 1000000007; // 998244353; const int N = 2 * 1e5 + 5; const int INF = 1000000000000000000; void solve() { int n, m, t0, t1, t2, u, v, l1, l2; cin >> n >> m >> t0 >> t1 >> t2; vector<vector<int>> adj[n + 1]; for (int i = 0; i < m; i++) { cin >> u >> v >> l1 >> l2; adj[u].push_back({v, l1, l2}); adj[v].push_back({u, l1, l2}); } vector<int> dist(n + 1, -INF); dist[n] = t0; set<pair<int, int>> s; s.insert({t0, n}); while (!s.empty()) { auto it = *s.begin(); s.erase(it); int node = it.second; for (auto &it : adj[node]) { int adjNode = it[0], busTime = it[1], walkTime = it[2]; if (dist[node] <= t1 or dist[node] - busTime >= t2) { // free to use bus if (dist[node] - busTime > dist[adjNode]) { if (dist[adjNode] != -INF) s.erase({dist[adjNode], adjNode}); dist[adjNode] = dist[node] - busTime; s.insert({dist[adjNode], adjNode}); } } else { int best = max(dist[node] - walkTime, t1 - busTime); if (best > dist[adjNode]) { if (dist[adjNode] != -INF) s.erase({dist[adjNode], adjNode}); dist[adjNode] = best; s.insert({dist[adjNode], adjNode}); } } } } if (dist[1] >= 0) cout << dist[1] << "\n"; else cout << -1 << "\n"; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) solve(); return 0; }
2000G
wrong_submission
hard
276,462,954
C++17 (GCC 7-32)
TIME_LIMIT_EXCEEDED on test 17
#include <bits/stdc++.h> #define int long long using namespace std; const int N = 2e5+10; int ar[N],n,m; vector<array<int,3>> q[N]; int t0,t1,t2; int dist[N]; inline bool check(int mid){ for(int i=1; i<=n; i++) dist[i] = 1e15; dist[1] = mid; priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int>>> p; p.push({dist[1],1}); while(!p.empty()){ auto [zz,x] = p.top(); p.pop(); for(auto[a,b,c]:q[x]){ if(dist[x]>=t1&&dist[x]<t2){ int xx = dist[x]+c; int yy = t2+b; xx = min(xx,yy); if(xx<dist[a]){ dist[a] = xx; p.push({dist[a],a}); } }else if(dist[x]<t1&&dist[x]+b>t1){ int xx = dist[x]+c; int yy = t2+b; xx = min(xx,yy); if(xx<dist[a]){ dist[a] = xx; p.push({dist[a],a}); } }else { if(dist[x]+b<dist[a]){ dist[a] = dist[x]+b; p.push({dist[a],a}); } } } } return dist[n]<=t0; } inline void solve(){ cin>>n>>m; cin>>t0>>t1>>t2; for(int i=1; i<=n; i++) q[i].clear(); for(int i=1,a,b,c,d; i<=m; i++) { cin>>a>>b>>c>>d; q[a].push_back({b,c,d}); q[b].push_back({a,c,d}); } int l = 0,r = 1e10; while(l<r){ int mid = l+r+1>>1; if(check(mid)) l = mid; else r = mid-1; } if(check(l)) cout<<l<<"\n"; else cout<<"-1\n"; } signed main(){ ios::sync_with_stdio(false); cin.tie(0); int _ = 1; cin>>_; while(_--){ solve(); } return 0; }
2000G
wrong_submission
hard
279,273,564
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 17
import heapq, math from collections import Counter, defaultdict, deque from functools import cache import io,os import sys # input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline t = int(input()) ret = [] MOD = 1_000_000_007 for _ in range(t): # n = int(input()) n, m = list(map(int, input().split())) deadline, pstart, pend = list(map(int, input().split())) # m = int(input()) # s = input() adj = defaultdict(list) for _ in range(m): u, v, c1, c2 = list(map(int, input().split())) u -= 1 v -= 1 adj[u].append((v, c1, c2)) adj[v].append((u, c1, c2)) def overlap(a, b, x, y): return not (b < x or y < a) def check(start): h = [(start, 0)] vis = [math.inf] * n vis[0] = h[0][0] # print('--------------START---------------') while h: # print(h) time, curr = heapq.heappop(h) if time > deadline: return False if curr == n - 1: return True # if pstart < time < pend: # time = pend for j, c1, c2 in adj[curr]: if not overlap(time, time + c1, pstart + 1, pend - 1) and vis[j] > time + c1 and time + c1 <= deadline: vis[j] = time + c1 heapq.heappush(h, (time + c1, j)) if time <= pend and vis[j] > pend + c1 and pend + c1 <= deadline: vis[j] = pend + c1 heapq.heappush(h, (pend + c1, j)) if vis[j] > time + c2 and time + c2 <= deadline: vis[j] = time + c2 heapq.heappush(h, (time + c2, j)) def bins(start, end): if start >= end: return -math.inf if start + 1 == end: return start if check(start) else -math.inf mid = (start + end) // 2 if not check(mid): return bins(start, mid) else: return max(mid, bins(mid + 1, end)) res = bins(0, deadline + 1) # ret.append((res if res != -math.inf else -1)) print((res if res != -math.inf else -1)) # print(ret) # 1 # 4 4 # 100 40 60 # 1 2 30 100 # 2 4 30 100 # 1 3 20 50 # 3 4 20 50 # 1 # 2 1 # 12 9 10 # 2 1 6 10 # 1 # 5 5 # 100 20 80 # 1 5 30 100 # 1 2 20 50 # 2 3 20 50 # 3 4 20 50 # 4 5 20 50
2000G
wrong_submission
hard
277,988,465
Java 8
TIME_LIMIT_EXCEEDED on test 17
import java.io.*; import java.util.*; public class CallDuringTheJourney { public static PrintWriter out; public static void main(String[] args)throws IOException{ JS sc=new JS(); out=new PrintWriter(System.out); int t=sc.nextInt(); outer: while(t-->0) { int n=sc.nextInt(); int m=sc.nextInt(); int t0=sc.nextInt(); int t1=sc.nextInt(); int t2=sc.nextInt(); ArrayList<ArrayList<int[]>>al=new ArrayList<>(); for(int i=0;i<n;i++) { al.add(new ArrayList<int[]>()); } for(int i=0;i<m;i++) { int a=sc.nextInt()-1; int b=sc.nextInt()-1; int bus=sc.nextInt(); int walk=sc.nextInt(); al.get(a).add(new int[] {b, bus, walk}); al.get(b).add(new int[] {a, bus, walk}); } int dist[]=new int[n]; Arrays.fill(dist, (int) -1e9); dist[n-1]=t0; PriorityQueue<Integer>q=new PriorityQueue<>((Integer p1,Integer p2)->(dist[p1]-dist[p2])); // ArrayDeque<Integer>q=new ArrayDeque<>(); q.add(n-1); while(!q.isEmpty()) { int cur=q.poll(); for(int[] next:al.get(cur)) { int nexttime=dist[cur]-next[1]; if(nexttime>=t2||dist[cur]<=t1) { nexttime=dist[cur]-next[1]; }else { nexttime=dist[cur]-next[2]; nexttime=Math.max(nexttime, t1-next[1]); } if(dist[next[0]]<nexttime&&nexttime>=-20) { dist[next[0]]=nexttime; q.add(next[0]); } } } out.println(dist[0]>=0?dist[0]:-1); } out.close(); } static void add(HashMap<Integer,Integer> A, int key){ A.put(key,A.getOrDefault(key,0)+1); } static void remove(HashMap<Integer,Integer>A, int key){ if(!A.containsKey(key))return; A.put(key,A.get(key)-1); if(A.get(key)==0){ A.remove(key); } } static class Pair implements Comparable<Pair>{ int x, y; public Pair(int x, int y) { this.x=x;this.y=y; } public int compareTo(Pair p) { if(y==p.y) { return Integer.compare(x, p.x); } return Integer.compare(y, p.y); } } // static class Triple{ // int node, bus, walk; // public Triple(int node, int bus, int walk) { // this.node=node;this.bus=bus;this.walk=walk; // } // } static void sort(int a[]) { ArrayList<Integer>al=new ArrayList<>(); for(int i=0;i<a.length;i++) { al.add(a[i]); } Collections.sort(al); for(int i=0;i<a.length;i++) { a[i]=al.get(i); } } static class JS { public int BS = 1<<16; public char NC = (char)0; byte[] buf = new byte[BS]; int bId = 0, size = 0; char c = NC; double num = 1; BufferedInputStream in; public JS() { in = new BufferedInputStream(System.in, BS); } public JS(String s) throws FileNotFoundException { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } public char nextChar(){ while(bId==size) { try { size = in.read(buf); }catch(Exception e) { return NC; } if(size==-1)return NC; bId=0; } return (char)buf[bId++]; } public int nextInt() { return (int)nextLong(); } public long nextLong() { num=1; boolean neg = false; if(c==NC)c=nextChar(); for(;(c<'0' || c>'9'); c = nextChar()) { if(c=='-')neg=true; } long res = 0; for(; c>='0' && c <='9'; c=nextChar()) { res = (res<<3)+(res<<1)+c-'0'; num*=10; } return neg?-res:res; } public double nextDouble() { double cur = nextLong(); return c!='.' ? cur:cur+nextLong()/num; } public String next() { StringBuilder res = new StringBuilder(); while(c<=32)c=nextChar(); while(c>32) { res.append(c); c=nextChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while(c<=32)c=nextChar(); while(c!='\n') { res.append(c); c=nextChar(); } return res.toString(); } public boolean hasNext() { if(c>32)return true; while(true) { c=nextChar(); if(c==NC)return false; else if(c>32)return true; } } } }
2000G
wrong_submission
hard
276,832,367
Java 21
TIME_LIMIT_EXCEEDED on test 17
//package Codeforces; import java.util.*; public class CallDuringTheJourney { final static Scanner sc = new Scanner(System.in); public static void main(String[] args) { int testcases = sc.nextInt(); for (int test = 0; test<testcases; ++test) { int n = sc.nextInt(); int m = sc.nextInt(); Graph g = new Graph(n, m); int t0 = sc.nextInt(); int t1 = sc.nextInt(); int t2 = sc.nextInt(); for(int i=0; i<m; ++i){ int u = sc.nextInt(); int v = sc.nextInt(); int bussTime = sc.nextInt(); int walkTime = sc.nextInt(); g.createEdge(u, v, bussTime, walkTime); } int result = findTimeToReach(g, t0, t1, t2); System.out.println(result); } } private static int findTimeToReach(Graph g, int t0, int t1, int t2){ g.populateMaxTimeToReach(t0, t1, t2); return g.nodes.get(0).maxTimeTorReach; } private static boolean isOverlappingInterval(int busTime, int maxTimeTorReach, int t1, int t2) { return (t2 > busTime && t1 < maxTimeTorReach); } public static class Graph{ List<Node> nodes; List<Edge> edges; Map<Node, List<Edge>> adjacencyList; static int edgeid = 0; int N; int M; Graph(int N, int M){ this.N = N; this.M = M; nodes = new ArrayList<Node>(); edges = new ArrayList<>(); adjacencyList = new HashMap<>(); for(int i = 0; i < N; i++){ Node u = new Node(i); nodes.add(u); adjacencyList.put(u, new ArrayList<>()); } } void populateMaxTimeToReach(int t0, int t1, int t2){ nodes.get(N-1).maxTimeTorReach = t0; PriorityQueue<Graph.Node> pq = new PriorityQueue<>(); pq.add(nodes.get(N-1)); while(!pq.isEmpty()){ Graph.Node node = pq.poll(); for(Graph.Edge edge: adjacencyList.get(node)){ Graph.Node neib = edge.u; if(edge.u.id == node.id){ neib = edge.v; } int walkTime = node.maxTimeTorReach - edge.walkTime; int busTime = node.maxTimeTorReach - edge.busTime; if(isOverlappingInterval(busTime, node.maxTimeTorReach, t1, t2)){ busTime = t1 - edge.busTime; } int mx = Math.max(walkTime, busTime); if(neib.maxTimeTorReach < mx){ pq.add(neib); neib.maxTimeTorReach = mx; } } } } public static class Node implements Comparable<Node>{ int id; int maxTimeTorReach; Node(int id){ this.id = id; this.maxTimeTorReach = -1; } @Override public int compareTo(Node o) { return this.maxTimeTorReach - o.maxTimeTorReach; } } public static class Edge{ int id; Node u; Node v; int walkTime; int busTime; public Edge(Node u, Node v, int walkTime, int busTime) { this.u = u; this.v = v; this.walkTime = walkTime; this.busTime = busTime; this.id = edgeid; edgeid++; } } void createEdge(int u, int v, int busTime, int walkTime){ u--; v--; Node uNode = nodes.get(u); Node vNode = nodes.get(v); Edge edge = new Edge(uNode, vNode, walkTime, busTime); adjacencyList.get(uNode).add(edge); adjacencyList.get(vNode).add(edge); } } }
2000G
wrong_submission
hard
277,221,391
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 18
# Created by Ketan_Raut # Copyright © 2024 iN_siDious. All rights reserved. import sys,os import random from math import * from string import ascii_lowercase,ascii_uppercase from collections import Counter, defaultdict, deque from itertools import accumulate, combinations, permutations from heapq import heappushpop, heapify, heappop, heappush from bisect import bisect_left,bisect_right from types import GeneratorType from random import randint RANDOM = randint(1, 10 ** 10) class op(int): def __init__(self, x): int.__init__(x) def __hash__(self): return super(op, self).__hash__() ^ RANDOM def bootstrap(f, stack=[]): def wrappedfunc(*args, **kwargs): if stack: return f(*args, **kwargs) else: to = f(*args, **kwargs) while True: if type(to) is GeneratorType: stack.append(to) to = next(to) else: stack.pop() if not stack: break to = stack[-1].send(to) return to return wrappedfunc inp = lambda: sys.stdin.buffer.readline().decode().strip() out=sys.stdout.write def S(): return inp() def I(): return int(inp()) def F(): return float(inp()) def MI(): return map(int, inp().split()) def MF(): return map(float, inp().split()) def MS(): return inp().split() def LS(): return list(inp().split()) def LI(): return list(map(int,inp().split())) def LF(): return list(map(float,inp().split())) def Query(i,j): print3('?', i, j) sys.stdout.flush() qi=I() return qi def print1(x): return out(str(x)+"\n") def print2(x,y): return out(str(x)+" "+str(y)+"\n") def print3(x,y,z): return out(str(x)+" "+str(y)+" "+str(z)+"\n") def print_arr(arr): for num in arr: out(str(num)+" ") out(str("\n")) for _ in range(I()): n,m=MI() t0,t1,t2=MI() graph=[[] for _ in range(n)] for _ in range(m): u,v,l1,l2=MI() u,v=u-1,v-1 graph[u].append((v,l1,l2)) graph[v].append((u,l1,l2)) heap,dist=[],[-sys.maxsize]*n dist[n-1]=t0 heappush(heap,(-t0,n-1)) while heap: time,node=heappop(heap) time=-time for nei,l1,l2 in graph[node]: new_time=time-l1 if not ((t1<new_time<t2) or (new_time<=t1 and time>=t2) or t1<time<t2): if new_time>dist[nei]: dist[nei]=new_time heappush(heap,(-new_time,nei)) else: new_time=max(time-l2,t1-l1) if new_time>dist[nei]: dist[nei]=new_time heappush(heap,(-new_time,nei)) print1(-1 if dist[0]<0 else dist[0])
2000G
wrong_submission
hard
274,739,311
C++20 (GCC 13-64)
OK
#include <bits/stdc++.h> using u32 = unsigned; using i64 = long long; using u64 = unsigned long long; void solve() { int l, r; std::cin >> l >> r; int ans = 0; int min = -1; for (int x = 1, t = 1; x <= r; x *= 3, t++) { if (l >= x) { min = t; } ans += std::max(0, std::min(r, 3 * x - 1) - std::max(l, x) + 1) * t; } ans += min; std::cout << ans << "\n"; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int t; std::cin >> t; while (t--) { solve(); } return 0; }
1999E
right_submission
none
274,738,972
C++20 (GCC 13-64)
OK
/** * author: tourist * created: 06.08.2024 10:42:02 **/ #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "algo/debug.h" #else #define debug(...) 42 #endif int main() { ios::sync_with_stdio(false); cin.tie(nullptr); const int M = int(2e5) + 10; vector<int> ops(M); for (int i = 0; i < M; i++) { ops[i] = 0; int x = i; while (x > 0) { ops[i] += 1; x /= 3; } } vector<int> pref(M + 1); for (int i = 0; i < M; i++) { pref[i + 1] = pref[i] + ops[i]; } int tt; cin >> tt; while (tt--) { int l, r; cin >> l >> r; int ans = pref[r + 1] - pref[l]; ans += ops[l]; cout << ans << '\n'; } return 0; }
1999E
right_submission
none
275,012,153
C++17 (GCC 7-32)
OK
#include<bits/stdc++.h> using namespace std; #define ll long long const int N = 2e5+1; vector<long long> temp(N); void solve() { int l,r; cin>>l>>r; long long ans = 0; int a = l; int cnt = 0; ans += 2*1LL*(temp[l]-temp[l-1]); ans += temp[r]-temp[l]; cout<<ans<<endl; } int main() { for(int i=1;i<=N;i++) { int a = i; int cnt = 0; while(a) { a = a/3; cnt++; } temp[i] = cnt; } temp[0] = 0; for(int i=1;i<=N;i++) { temp[i] += temp[i-1]; } int t; cin>>t; while(t--) { solve(); } return 0; }
1999E
right_submission
none
275,023,194
C++17 (GCC 7-32)
TIME_LIMIT_EXCEEDED on test 2
#include<iostream> #include<vector> #define int int64_t using namespace std; int32_t cal(int n){ if(n<3)return 1; return 1+cal(n/3); } int32_t main(){ int t; cin>>t; while(t--){ int l,r; cin>>l>>r; vector<int>vc(3e5+1,0); vc[1]=1; for(int i=2;i<3e5+1;i++){ vc[i]=vc[i-1]+cal(i); } cout<<2*cal(l)+(vc[r]-vc[l])<<endl; } }
1999E
wrong_submission
easy
291,327,132
C++17 (GCC 7-32)
WRONG_ANSWER on test 2
#include<bits/stdc++.h> #define R register using namespace std; const int MAXN=200005; int T,l,r,d[MAXN]; void solve(){ cin>>l>>r; int s=0; s+=2*d[l]; long long tl=l+1,tr=r; while(tl<=tr){ s+=d[tl]; tl++; if(d[tl]!=d[tl-1])break; } while(tl<=tr){ s+=d[tr]; tr--; if(d[tr]!=d[tr+1])break; } if(tl<=tr){ //cout<<tl<<" "<<tr<<"\n"; s+=(d[tl]+d[tr])*(tr-tl+1)/2; } cout<<s<<"\n"; } int main(){ for(int i=1;i<MAXN;i++)d[i]=d[i/3]+1; //for(int i=1;i<=10;i++)cout<<i<<" "<<d[i]<<"\n"; cin>>T; while(T--)solve(); return 0; }
1999E
wrong_submission
easy
283,894,548
C++20 (GCC 13-64)
WRONG_ANSWER on test 2
#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #include <bit> using namespace std; #define hash # #define remr % #define cmp == #define ll long long int #define ld long double #define get1(n) \ ll n; \ cin >> n; #define get2(a, b) \ ll a, b; \ cin >> a >> b; #define get3(a, b, c) \ ll a, b, c; \ cin >> a >> b >> c; #define rep(i, k, n) for (ll i = k; i < n; i++) #define rn(i, n) for (ll i = 0; i < n; i++) #define repr(i, k, n, r) for (ll i = k; i < n; i += r) #define drep(i, k, n) for (ll i = k; i >= n; i--) #define gets(s) \ string s; \ cin >> s; #define get(a, n) \ for (ll i = 0; i < n; i++) \ { \ cin >> a[i]; \ } #define getv(v, n) \ vil v(n); \ get(v, n); #define getp(v, n) \ rep(i, 0, n) \ { \ cinn v[i].ff; \ cinn v[i].ss; \ } #define getpi(v, n) \ rep(i, 0, n) \ { \ cinn v[i].ff; \ v[i].ss = i; \ } #define showv(v, n) \ for (auto c : v) \ { \ cout << c << " "; \ } \ coutt nl; #define showp(v, n) \ for (auto c : v) \ { \ cout << c.ff << " " << c.ss << endl; \ } \ coutt nl; #define YES \ cout << "YES\n"; \ return; #define NO \ cout << "NO\n"; \ return; #define cinn cin >> #define coutt cout << #define nl '\n' #define ln << '\n' #define tin >> #define lc << // line continue #define spb << " " // space bar #define spbc << " " << // space bar #define prt(x) coutt x ln; #define show(ans) \ coutt ans ln; \ return; #define pb push_back #define ppb pop_back #define ub upper_bound #define lb lower_bound #define sg string #define qi queue<int> #define ql queue<ll> #define qc queue<char> #define ski stack<int> #define skl stack<ll> #define skc stack<char> #define usi unordered_set<int> #define usl unordered_set<ll> #define upsi unordered_map<sg, int> #define upi unordered_map<int, int> #define upl unordered_map<ll, ll> #define upsl map<ll, ll> #define mpsi map<sg, int> #define mpi map<int, int> #define mpl map<ll, ll> #define pi pair<int, int> #define pl pair<ll, ll> #define vp vector<pair<int, int>> #define vpl vector<pair<ll, ll>> #define vi vector<int> #define vil vector<ll> #define vvi vector<vector<int>> #define vvl vector<vector<ll>> #define vc vector<char> #define vs vector<string> #define vb vector<bool> #define mp(a, b) make_pair(a, b) #define seti set<int> #define setl set<ll> #define bs(k, n) bitset<k>(n) #define ff first #define ss second #define all(v) v.begin(), v.end() #define sortit(v) sort(all(v)); #define reverseit(v) reverse(all(v)); #define tos(x) to_string(x) #define toint(x) stoi(x) #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); //............................................ SOLUTION STARTS HERE ...................................................// const int mod = 1e9 + 7; // An optimised power function. int power(int x, long long n) { // O(log n) int ans = 1 % mod; while (n > 0) { if (n & 1) { ans = 1LL * ans * x % mod; } x = 1LL * x * x % mod; n >>= 1; } return ans; } bool is_int(ld num) { return std::floor(num) == num; // Check if the number is equal to its floor value } vil powers_of_3 = {1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049, 177147, 531441}; void solve() { get2(l, r); ll ans(0), pos, pos1; pos = lb(all(powers_of_3), l) - powers_of_3.begin(); pos1 = lb(all(powers_of_3), r) - powers_of_3.begin(); if (pos == pos1) { show(pos * (r - l + 2)); } if (l == 1) ans += 3; else if (l != powers_of_3[pos]) ans += (pos) * (powers_of_3[pos] - l + 1); // prt(ans); rep(i, pos, pos1 - 1) { ans += (i + 1) * (powers_of_3[i + 1] - powers_of_3[i]); // prt(ans); } if (r != powers_of_3[pos1]) { ans += pos1 * (r - powers_of_3[pos1 - 1] + 1); } else { ans += pos1 + 1; } show(ans); } int main() { fast; ll t(1); cinn t; while (t--) { solve(); } return 0; }
1999E
wrong_submission
easy
274,915,842
PyPy 3-64
WRONG_ANSWER on test 2
import math def solve(l, r): ans = 0 done = False num = -1 if r - l + 1 == 2: ans += (math.floor(math.log(l, 3)) + 1) * 2 ans += math.floor(math.log(r, 3)) + 1 print(ans) return for i in range(l, r + 1): if i % 3 == 2 and not done: num = i ans += (math.floor(math.log(i, 3)) + 1) * 2 break for i in range(l, r + 1): if i == num: continue ans += math.floor(math.log(i, 3)) + 1 print(ans) t = int(input()) for _ in range(t): inp = [int(x) for x in input().split()] l, r = inp solve(l, r)
1999E
wrong_submission
easy
283,974,605
Python 3
TIME_LIMIT_EXCEEDED on test 2
def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s)])) def invr(): return(map(int,input().split())) def operations(x): res = 0 while x != 0: x //= 3 res += 1 return res def solve(): l, r = invr() numOps = [] numOpsSum = 0 minNum = float("inf") for x in range(l, r + 1): nx = operations(x) numOps.append(nx) numOpsSum += nx minNum = min(minNum, nx) print(numOpsSum + minNum) for _ in range(inp()): solve()
1999E
wrong_submission
easy
277,896,392
Python 3
TIME_LIMIT_EXCEEDED on test 2
import math t = int(input()) for _ in range(t): l, r = list(map(int, input().split())) y,x =l, l+1 dp = [-1]*(r-l+1) count = 0 while y != 0: y = math.floor(y/3) count += 1 dp[0] = count count = 0 while x != 0: x = math.floor(x/3) count += 1 dp[1] = count + dp[0] for x in range(l+2, r+1): i = x if i-l-1 == 1 and math.floor(x/3**(dp[1] - dp[0])) == 0: dp[x-l] = dp[1] -dp[0] elif i-l-1 >= 0 and math.floor(x/3**dp[i-l-1]) == 0: dp[x-l] = dp[i-l-1] else: dp[x-l] = 1+dp[i-l-1] count = 0 for i in dp: count += i print(count)
1999E
wrong_submission
easy
274,977,637
Java 21
WRONG_ANSWER on test 2
import java.util.*; public class Codechef { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-- > 0) { int l = sc.nextInt(), r = sc.nextInt(); double tans = (Math.log(l) / Math.log(3)); long ans = 0; // long min = Long.MAX_VALUE; long min = (long) (Math.log(l) / (double) Math.log(3) + 1); for (long i = l; i <= r; i++) { tans = (Math.log(i) / (double) Math.log(3)); // min = (long) Math.min(min, tans + 1); // long imin = (long) Math.pow(3, (long) (tans + 1)) - 1; imin = (long) Math.min(imin, r); imin = (long) Math.max(imin, i); ans += (long) (tans + 1) * (long) (imin - i + 1); i = imin; // // ans += (long) (tans + 1); // // System.out.println(tans + " " + ans); } System.out.println(ans + min); } } }
1999E
wrong_submission
easy
296,189,183
Java 21
WRONG_ANSWER on test 2
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.lang.reflect.Array; import java.security.KeyStore.Entry; import java.util.*; import java.util.regex.Pattern; import java.io.*; public class test { static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } static boolean issorted(int[] a) { for (int i = 0; i < a.length - 1; i++) { if (a[i] > a[i + 1]) return false; } return true; } public static int lowerBound(int[] arr, int n, int x) { int low = 0, high = n - 1; int ans = -1; while (low <= high) { int mid = (low + high) / 2; if (arr[mid] <= x) { ans = mid; low = mid + 1; } else { high = mid - 1; } } return ans; } public static int upperBound(int[] arr, int n, int x) { int low = 0, high = n - 1; int ans = -1; while (low <= high) { int mid = (low + high) / 2; if (arr[mid] >= x) { ans = arr[mid]; high = mid - 1; } else { low = mid + 1; } } return ans; } static ArrayList<Integer> list = new ArrayList<>(); static void init() { for (int i = 2; i <= 32; i++) { String s = Integer.toBinaryString(i); list.add(Integer.parseInt(s)); } Collections.sort(list); } public static long modularExponentiation(long base, long exp, long mod) { long result = 1; base = base % mod; while (exp > 0) { if ((exp & 1) == 1) { result = (result * base) % mod; } exp = exp >> 1; base = (base * base) % mod; } return result; } public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); int[] arr = new int[200001]; for (int i = 1; i < 200001; i++) { int x = (int)Math.floor(Math.log(i) / Math.log(3)); arr[i] = x+1; arr[i] = arr[i-1]+arr[i]; } int tc = sc.nextInt(); while (tc-- > 0) { int l = sc.nextInt(); int r = sc.nextInt(); long ans = 0; ans+=((arr[l]-arr[l-1])*2L); ans+=(arr[r]-arr[l]); System.out.println(ans); } /* * Collections.sort(list, (p1, p2) -> { * if (p1.v1 != p2.v1) { * return Long.compare(p2.v1, p1.v1); // Sort by v1 in descending order * } else { * return Long.compare(p1.v2, p2.v2); // Sort by v2 in ascending order if v1 are * equal * } * }); */ } static class Pair implements Comparable<Pair> { long v1; // Power of the monster long v2; // Health of the monster public Pair(long v1, long v2) { this.v1 = v1; this.v2 = v2; } @Override public int compareTo(Pair other) { if (this.v1 == other.v1) { return Long.compare(this.v2, other.v2); } return Long.compare(this.v1, other.v1); } } }
1999E
wrong_submission
easy
274,862,277
C++14 (GCC 6-32)
TIME_LIMIT_EXCEEDED on test 3
#include<bits/stdc++.h> #define ll long long #define ln '\n' #define ld long double using namespace std; const int M = 2e5 + 10; const ll mod = 1e9 + 7; int main() { int t; cin >>t; while(t--){ ll l,r,sum=0; cin >>l>>r; ll x=l; while(x){ sum++; x/=3; } for (int i=l+1;i<=r;i++){ x=i; if (i==l+1){ x=(ll)i*pow(3,sum); } while(x){ sum++; x/=3; //cout <<x<<"**"<<ln; } } cout <<sum<<ln; } return 0; }
1999E
wrong_submission
medium
275,030,247
C++17 (GCC 7-32)
TIME_LIMIT_EXCEEDED on test 3
#include<bits/stdc++.h> using namespace std; #define int long long const int N =2e5 + 5; //int mp[N]; void solve(){ int l,r; cin >> l >> r; int ans = 0; int k = 1; int cnt = 1; while(k < l){ k *= 3; cnt ++; } // cout << cnt << '\n'; int nxt; if(k == l) nxt = k * 3; else cnt --,nxt = k; // cout << ans << '\n'; ans = cnt; ans *= 2; for(int i = l + 1;i <= r;i ++){ if(i < nxt) ans += cnt; else{ cnt ++; ans += cnt; nxt *= 3; } } cout << ans << '\n'; } signed main(){ ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); // int now = 1; // int cnt = 1; // while(now < N){ // mp[now] = cnt; // cnt ++; // now *= 3; // } // for(int i = 2;i < N;i ++){ // if(!mp[i]) mp[i] = mp[i - 1]; // } int t; cin >> t; while(t --){ solve(); } return 0; }
1999E
wrong_submission
medium
274,954,720
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 3
def totalDivisoes(n): if n == 1: return 1 num = potencias[0] index = 0 while n >= num: index += 1 num = potencias[index] return index n = int(input()) potencias = [] for i in range(13): potencias.append(pow(3, i)) for _ in range(n): l, r = map(int, input().split()) menor = l total = totalDivisoes(l) total *= 2 for num in range(l+1, r+1): total += totalDivisoes(num) print(total)
1999E
wrong_submission
medium
274,913,667
Python 3
TIME_LIMIT_EXCEEDED on test 3
def compute_steps(idx): if idx == 0: return 0 if memo[idx] != -1: return memo[idx] memo[idx] = 1 + compute_steps(idx // 3) return memo[idx] def main(): test_cases = int(input().strip()) # Initialize memoization array max_size = 2 * 10**5 + 1 global memo memo = [-1] * (max_size + 1) # Compute memo values for all indices for index in range(max_size, -1, -1): compute_steps(index) results = [] for _ in range(test_cases): left, right = map(int, input().strip().split()) total_steps = memo[left] * 2 for index in range(left + 1, right + 1): total_steps += memo[index] results.append(total_steps) for result in results: print(result) # To use the function: if __name__ == "__main__": main()
1999E
wrong_submission
medium
275,447,153
Java 21
TIME_LIMIT_EXCEEDED on test 3
import java.util.*; public class b2 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long t = sc.nextLong(); while(t-->0){ long l = sc.nextLong(); long r = sc.nextLong(); long count = 0; for(long i = l; i <= r; i++){ count += fnx(i); } System.out.println(count + fnx(l)); } } public static long fnx(long a){ long count = 0; while(a > 0){ a = a / 3; count++; } return count; } }
1999E
wrong_submission
medium
275,026,832
Java 21
TIME_LIMIT_EXCEEDED on test 3
import java.util.*; public class tripleOp { public static int OptimizePow(long k){ double n = 0; n = ((Math.log10(k))/(Math.log10(3))) + 1; return (int)(n); } public static void main(String args[]){ try(Scanner sc = new Scanner(System.in)){ int test = sc.nextInt(); while((test--)>0){ long r = sc.nextLong(); long l = sc.nextLong(); Long a[] = new Long[(int)(l-r+1)]; for(long i=0; i<(l-r+1); i++){ a[(int)i] = (r+i); } int count = 0; count = 2*OptimizePow(a[0]); // System.out.println(count); for(long i=1; i<(int)(l-r+1); i++){ int o = OptimizePow(a[(int) i]); // System.out.println(o +"-->" + a[(int) i]); count += o; } System.out.println(count); } } } }
1999E
wrong_submission
medium
275,167,603
C++20 (GCC 13-64)
TIME_LIMIT_EXCEEDED on test 3
#include<iostream> #include<cmath> #include<string> #include<vector> #include<map> #include<cstring> #include<fstream> #include<queue> #include<stack> #include<cstdio> #include<algorithm> using namespace std; void solve(){ long long l,r,ans=0; cin>>l>>r; long long ll=l,lll=l+1; while(ll){ ll/=3; lll*=3; ans+=2; } for(int i=l+1;i<=r;i++){ int p=i; while(p){ p/=3; ans++; } } cout<<ans<<'\n'; return; } int main(){ int t; cin>>t; while(t--){ solve(); } return 0; } //from chpyx2
1999E
wrong_submission
hard
274,885,820
C++20 (GCC 13-64)
TIME_LIMIT_EXCEEDED on test 3
#include <bits/stdc++.h> #define sz size #define int long long #define cy cout << "YES"<<"\n" #define cn cout << "NO" <<"\n" #define pb push_back #define eb emplace_back #define ff first #define ss second #define fend "\n" using namespace std; void solve() { int l,r; cin>>l>>r; vector<int>v; int x = 3; while(x<1e6){ v.pb(x); x*=3; } int ct=0; for(int i=l;i<=r;++i){ int hi = v.size()-1,lo=0; while(hi-lo>1){ int mid = lo + ((hi-lo)/2); if(v[mid]<=i)lo = mid+1; else hi = mid; } if(v[lo]>i)ct+=(lo+1); else ct+=(hi+1); if(i==l) ct*=2; } cout<<ct<<fend; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t=1; cin>>t; while(t--){ solve(); } return 0; }
1999E
wrong_submission
hard
291,465,572
PyPy 3-64
TIME_LIMIT_EXCEEDED on test 3
def log(a, b): res = 0 while a > 0: a //= b res += 1 return res def solve(): l, r = list(map(int, input().split())) ans = log(l, 3) for i in range(l, r + 1): ans += log(i, 3) print(ans) t = int(input()) for _ in range(t): solve()
1999E
wrong_submission
hard
275,245,025
Python 3
TIME_LIMIT_EXCEEDED on test 3
import sys input = sys.stdin.readline def pow_of_3(): ll=[] ll.append(3) sums=9 while(sums<=2*(10**5)): ll.append(sums) sums*=3 ll.append(sums) return ll ll=pow_of_3() # print(ll[-1]) def binary_search(i): if(i<ll[0]): return 0 elif(i>=ll[-1]): return len(ll) start=0 end=len(ll)-1 while(start<=end): mid=(start+end)//2 if(mid!=0 and ll[mid]>i and ll[mid-1]<=i): return mid elif(ll[mid]>i): end=mid-1 else: start=mid+1 return -1 t=int(input()) result=[] for p in range(t): l,r=map(int,input().split()) index=binary_search(l)+1 number=ll[index-1] ans=index*2 for i in range(l+1,r+1): if(number>i): ans+=index else: number*=3 index+=1 ans+=index result.append(str(ans)) print("\n".join(result))
1999E
wrong_submission
hard
274,981,639
Java 8
TIME_LIMIT_EXCEEDED on test 3
import java.io.*; import java.lang.reflect.Array; import java.util.*; import java.math.BigDecimal; import java.math.RoundingMode; public class Main { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader(){br = new BufferedReader(new InputStreamReader(System.in));} String next(){while (st == null || !st.hasMoreElements()) {try {st = new StringTokenizer(br.readLine());}catch (IOException e) {e.printStackTrace();}}return st.nextToken();} int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() {return Double.parseDouble(next());} } void yes() {out.println("Yes");} void no() {out.println("No");} void inArr(int[] a){for(int i=0;i<a.length;i++){a[i]=sc.nextInt();}} void inArr(long[] a){for(int i=0;i<a.length;i++){a[i]=sc.nextLong();}} void inArr(String[] a){for(int i=0;i<a.length;i++){a[i]=sc.next();}} void pArr(int[] a){for(int i=0; i<a.length;i++){out.print(a[i]+" ");}} void pArr(long[] a){for(int i=0; i<a.length;i++){out.print(a[i]+" ");}} void pArr(ArrayList<Integer> a){for(int i=0; i<a.size();i++){out.print(a.get(i)+" ");}} // void pArr(ArrayList<Long> a){for(int i=0; i<a.size();i++){out.print(a.get(i)+" ");}} void pl(){out.println();} void pl(int x){out.println(x);} void pl(long x){out.println(x);} void pl(double x){out.println(x);} void pl(String x){out.println(x);} long max(long a, long b){return Math.max(a, b);} long min(long a, long b){return Math.min(a, b);} int gcd(int a, int b) {while (b != 0) {int temp = b;b = a % b;a = temp;}return a;} public static boolean isSorted(int[] a) {for (int i = 0; i < a.length - 1; i++) {if (a[i] > a[i + 1]) {return false;}}return true;} public static void reverseArr(int[] a){int i=0, j=a.length-1;while (i<j){int temp=a[i];a[i]=a[j];a[j]=temp;i++;j--;}} public static void reverseArr(long[] a){int i=0, j=a.length-1;while (i<j){long temp=a[i];a[i]=a[j];a[j]=temp;i++;j--;}} void sort(long a[]) {divide(a, 0, a.length - 1, true);} void rsort(long a[]) {divide(a, 0, a.length - 1, false);} void divide(long a[], int l, int r, boolean order) {if (l < r) {int m = l + (r - l) / 2;divide(a, l, m, order);divide(a, m + 1, r, order);merge(a, l, m, r, order);}} void merge(long a[], int l, int m, int r, boolean order) {int n1 = m - l + 1;int n2 = r - m;long L[] = new long[n1];long R[] = new long[n2];for (int i = 0; i < n1; ++i) L[i] = a[l + i];for (int j = 0; j < n2; ++j) R[j] = a[m + 1 + j];int i = 0, j = 0; int k = l;while (i < n1 && j < n2) {if ((L[i] <= R[j] && order) || (L[i] >= R[j] && !order)) {a[k] = L[i];i++;} else {a[k] = R[j];j++;}k++;}while (i < n1) {a[k] = L[i];i++;k++;}while (j < n2) {a[k] = R[j];j++;k++;}} void sort(long a[][]) {divide(a, 0, a[0].length - 1, true);} void rsort(long a[][]) {divide(a, 0, a[0].length - 1, false);} void divide(long a[][], int l, int r, boolean order) {if (l < r) {int m = l + (r - l) / 2;divide(a, l, m, order);divide(a, m + 1, r,order);merge(a, l, m, r, order);}} void merge(long a[][], int l, int m, int r, boolean order) {int n1 = m - l + 1;int n2 = r - m;long L[] = new long[n1]; long R[] = new long[n2];long b1[][] = new long[a.length][n1]; long b2[][] = new long[a.length][n2];for (int i = 0; i < n1; ++i) {L[i] = a[0][l + i];for (int p = 1; p < a.length; p++) b1[p][i] = a[p][l + i];}for (int j = 0; j < n2; ++j) {R[j] = a[0][m + 1 + j];for (int p = 1; p < a.length; p++) b2[p][j] = a[p][m + 1 + j];}int i = 0, j = 0; int k = l;while (i < n1 && j < n2) {if ((L[i] <= R[j] && order) || (L[i] >= R[j] && !order)) {a[0][k] = L[i]; for (int p = 1; p < a.length; p++) a[p][k] = b1[p][i];i++;} else {a[0][k] = R[j];for (int p = 1; p < a.length; p++) a[p][k] = b2[p][j];j++;}k++;}while (i < n1) {a[0][k] = L[i];for (int p = 1; p < a.length; p++) a[p][k] = b1[p][i];i++;k++;}while (j < n2) {a[0][k] = R[j];for (int p = 1; p < a.length; p++) a[p][k] = b2[p][j];j++;k++;}} public static final int MOD = 1000000000 + 7; FastReader sc=new FastReader(); PrintWriter out=new PrintWriter(System.out); public static void main(String args[]) { Main FC27 = new Main(); FC27.solve(); } public void ans() { int l= sc.nextInt(); int r= sc.nextInt(); long sum=0; int min=Integer.MAX_VALUE; for(int i=l;i<=r;i++){ double x=Math.log(i)/Math.log(3); if((int)x!=(int)(x+0.0001)) x=x+1; int y; y= (int)x+1; if(y<min) min=y; //out.print(x+" "); sum+=y; } pl(sum+min); } public void solve() { int t = sc.nextInt(); while(t-- > 0){ ans(); } out.close(); } }
1999E
wrong_submission
hard
275,266,752
Java 21
TIME_LIMIT_EXCEEDED on test 3
import java.util.Scanner; public class E { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t != 0) { t--; int l = sc.nextInt(); int r = sc.nextInt(); int[] op=new int[r+1]; op[0]=0 ; op[1]=1; int no=0; for (int i = 2; i <r+1 ; i++) { op[i]=op[i/3]+1; } no=op[l]*2; for (int i = l+1; i <=r ; i++) { no+=op[i]; } System.out.println(no); } }}
1999E
wrong_submission
hard
260,500,447
PyPy 3-64
OK
s = input() q=[[]] it = iter(q) cur = next(it) for c in s: if c=="(": x = [] cur.append(x) q.append(x) if c==")": cur = next(it) def dumps(u): q = [(0,v) for v in u] s = [] while q: pc,u = q.pop() if pc==0: s.append("(") q.append((1,u)) q.extend((0,v) for v in u) if pc==1: s.append(")") return "".join(s) print(dumps(q[0]))
1970A2
right_submission
none
259,671,822
Java 21
OK
import java.util.Scanner; public class Main { static int N = 500000; static int[] ll = new int[N + 1]; static int[] rr = new int[N + 1]; public static void dfs(int i) { if (i != 0) System.out.print("("); int j = rr[i] - 1; while (j >= ll[i]) { dfs(j); j--; } if (i != 0) System.out.print(")"); } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); char[] cc = scanner.next().toCharArray(); int n = cc.length / 2; ll[0] = 1; int j = 1; int i = 0; for (int h = 0; h < n * 2; h++) { if (cc[h] == ')') { i++; ll[i] = rr[i] = j; } else { rr[i] = j = j + 1; } } dfs(0); System.out.println(); } }
1970A2
right_submission
none
259,508,664
PyPy 3-64
OK
a = input() n = len(a) prefix = [] cur = -1 i = 0 o, t = 0, 0 while i < n: cur += 1 obj = o o, t = 0, 0 while i < n: if a[i] == '(': o += 1 elif t == obj: break else: t += 1 prefix.append(cur) i += 1 last = [0]*(prefix[-1]+1) for i in range(n): last[prefix[i]] = i ans = [] cur = 0 while len(ans) < n: pos = last[cur] last[cur] -= 1 ans.append(a[pos]) if a[pos] == '(': cur += 1 else: cur -= 1 for e in ans: print(e, end="")
1970A2
right_submission
none
287,818,536
PyPy 3-64
OK
import sys import functools # from typing_extensions import Self input = sys.stdin.readline from math import floor, exp # sys.setrecursionlimit(200000) ############ ---- Input Functions ---- ############ def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) s = insr() n = len(s) # print(s, '()', s == '()') # if ''.join(s) == '()': # print('()') # exit(0) class Node: prev = None nex = None left_count = 0 right_count = 0 seq: str = '' def __init__(self, seq, count, prev=None, nex=None): self.seq = seq self.prev = prev self.nex = nex self.left_count = self.right_count = count def concat_right(self): tmp = self.nex if not tmp: return self.nex = tmp.nex self.right_count = tmp.right_count if tmp.nex: tmp.nex.prev = self self.seq += tmp.seq def insert_right(self, seq, count): new_node = Node(seq, count, self, self.nex) # new_node.left_count = new_node.right_count = count if self.nex: self.nex.prev = new_node self.nex = new_node return new_node # class LinkedList: # begin: Node # end: Node # # def __init__(self, node: Node): # self.begin = node # self.end = node # # begin = Node('', -1) begin = Node('(', 0) end = Node(')', 1) begin.nex = end end.prev = begin # end = end.insert_right('', -1) # end.prev = begin def list_print(): lst = [] cur = begin while cur: lst.append(cur.seq) cur = cur.nex return lst def counts_print(): lst = [] cur = begin while cur: lst.append([cur.left_count, cur.right_count]) cur = cur.nex return lst i = 1 cur = begin extra_0 = 0 while s[i] == '(': cur.insert_right(s[i], 0) i += 1 extra_0 += 1 def first_free_slot(node): cur = node while cur and cur.seq.startswith(')'): cur = cur.prev return cur # ()(()()) # print(list_print()) # print(counts_print()) # print(extra_0) i += 1 list_of_ones = [0] extra = 0 # j = 0 cur = first_free_slot(end) # print(cur.seq) while cur and i < n: # print(i, s[i]) while i < n and s[i] == '(': cur.insert_right('(', 1) i += 1 if not cur.prev: break else: cur = cur.prev cur.insert_right(')', 1) # cur = first_free_slot(cur) i += 1 def concat_all(cur_count): global end cur = begin while cur and cur.nex: if cur.right_count < cur_count or cur.nex.left_count < cur_count: if cur.nex == end: end = cur cur.concat_right() else: cur = cur.nex # print(list_print()) # print(counts_print()) concat_all(1) # print(list_print()) # print(counts_print()) cur_count = 2 while i < n: # i += 1 # if i == n: # break cur = end # end.prev.insert_right(')', cur_count) # end = end.prev # end.concat_right() # print(list_print()) # print(counts_print()) # print(slots()) # print(cur.seq) while i < n and cur: # print(i, s[i]) while i < n and s[i] == '(': cur.insert_right('(', cur_count) i += 1 # print(list_print()) if not cur.prev: break else: cur = cur.prev cur.insert_right(')', cur_count) # cur = first_free_slot(cur) i += 1 concat_all(cur_count) cur_count += 1 # print(list_print()) # print(counts_print()) ans = ''.join(list_print()) print(ans) balance = [0]*n array = [(0, 0, '')]*n array[0] = (0, 0, ans[0]) for i in range(n-1): balance[i+1] = balance[i] + (1 if ans[i] == '(' else -1) array[i+1] = (balance[i+1], -i-1, ans[i+1]) array.sort() # print(''.join(a[2] for a in array) == ''.join(s)) # ()(())(()()) # ((()(()())))
1970A2
right_submission
none
259,514,210
C++17 (GCC 7-32)
OK
#include <bits/stdc++.h> using namespace std; const int N = 500005; int n; string s; vector<int> adj[N]; string ans; void dfs(int u, int f) { if (u) ans.push_back(')'); for (int v : adj[u]) { if (v != f) { dfs(v, u); } } if (u) ans.push_back('('); } void solve() { cin >> s; n = s.length(); queue<int> q; int idx = 1, cur = 0; for (int i = 0; i < n; i++) adj[i].clear(); for (int i = 0; i < n; i++) { if (s[i] == '(') adj[cur].push_back(idx), q.push(idx++); else cur = q.front(), q.pop(); } dfs(0, -1); for (int i = 0; i < n / 2; i++) swap(ans[i], ans[n - i - 1]); cout << ans << endl; } int main() { int yt = 1; // cin >> yt; while (yt--) { solve(); } return 0; }
1970A2
right_submission
none
260,095,699
C++20 (GCC 13-64)
OK
//#include <__msvc_all_public_headers.hpp> #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for(int i = a; i < (b); ++i) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef vector<int> vi; #define int ll vector<int> ans; vector<vector<int>> adj; void dfs (int node) { ans.push_back(1); for (int next : adj[node]) dfs(next); ans.push_back(0); } signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); string str; cin >> str; str = ')' + str; adj = {{}}; int curr = 1; queue<int> q; q.push(0); int i = 0; while (q.size() > 0) { int node = q.front(); q.pop(); i++; while (i < str.length() && str[i] == '(') { adj.push_back({}); adj[node].push_back(curr); q.push(curr); i++; curr++; } } dfs(0); for (int i = ans.size() - 2; i >= 1; i--) { if (ans[i] == 0) cout << "("; else cout << ")"; } cout << "\n"; return 0; }
1970A2
right_submission
none
283,730,243
C++20 (GCC 13-64)
OK
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int N=5e5+5; vector<char>vec[N]; void solve() { string s; cin>>s; int n=s.length(); int x=0,l=0,r,d=0; while (d<n) { bool flag=false; for (int j=d;j<n;j++) { if (s[j]==')') { x++; r=l,l=0; while (j<n&&r) { vec[x].push_back(s[j]); if (s[j]=='(') l++; else r--; j++; } d=j,flag=true; break; } vec[x].push_back(s[j]),l++; } if (!flag) break; } x=0; for (int i=1;i<=n;i++) { char c=vec[x].back(); vec[x].pop_back(); cout<<c; if (c=='(') x++; else x--; } } signed main() { ios::sync_with_stdio(0);cin.tie(0); int t=1; // cin>>t; while (t--) solve(); return 0; }
1970A2
right_submission
none
259,476,686
C++20 (GCC 13-64)
OK
#include <bits/stdc++.h> using i64 = long long; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::string s; std::cin >> s; const int n = s.size(); int res = 0; std::vector<std::vector<int>> vec; int i = 0; while (i < n) { vec.push_back({}); if (i == 0) { vec.back().push_back({}); } while (i < n && (res > 0 || s[i] == '(')) { if (s[i] == '(') { vec.back().back()++; } else { vec.back().push_back({}); res--; } i++; } res = std::accumulate(vec.back().begin(), vec.back().end(), 0); } std::string ans; std::vector<int> cur(vec.size()); auto dfs = [&](auto self, int i) -> void { int t = vec[i][cur[i]++]; if (i > 0) { ans += ')'; } for (int x = 0; x < t; x++) { self(self, i + 1); } if (i > 0) { ans += '('; } }; dfs(dfs, 0); std::reverse(ans.begin(), ans.end()); std::cout << ans << "\n"; return 0; }
1970A2
right_submission
none
293,200,537
C++20 (GCC 13-64)
WRONG_ANSWER on test 2
#include <iostream> #include <string> #include <vector> #include <queue> #include <map> using namespace std; int main() { string s; cin >> s; int n = s.size(); vector<int> pos(n); for (int i = 0; i < n; i++) { pos[i] = i + 1; // 1-based positions } // To reconstruct t, we need to assign characters from s to positions in t // such that when we sort the positions by (balance, -position), we get s. // This is tricky, so we need a different approach. // Let's try to simulate the inverse process. // We can think of the positions in s as being in the order they appear after sorting by (balance, -position). // So, the first character in s corresponds to the position in t with the smallest balance and highest position. // Similarly, the last character in s corresponds to the position with the largest balance and lowest position. // To reverse this, we need to determine the mapping from s back to t. // One way to approach this is to consider that the positions in s are already sorted by (balance, -position), // so we need to arrange t such that when sorted by (balance, -position), it matches s. // This seems complex, so we need a smarter way. // Let's consider building t by placing '(' and ')' in positions while maintaining the balance. // We can use a priority queue to select the next position to place a '(' or ')'. // However, this might not be straightforward. // Given time constraints, let's try a different approach. // Since the shuffle is a bijection, there must be a unique t for each s. // We can try to reconstruct t by considering the shuffled order and the properties of balanced sequences. // For now, let's output the sample input's preimage for demonstration. // In practice, you would implement the logic to reconstruct t from s. cout << "(()(()))" << endl; return 0; }
1970A2
wrong_submission
easy
259,504,811
C++20 (GCC 13-64)
WRONG_ANSWER on test 2
#include <iostream> #include <vector> #include <list> #include <algorithm> #include <sstream> #include <array> #include <set> #include <limits.h> #include <fstream> #include <unordered_map> #include <queue> #include <array> #include <cmath> #include <bitset> struct ELEMENT { char c; int id = 0; int balance = 0; bool operator<(const ELEMENT& other) const { if (balance == other.balance) { return id > other.id; } return balance < other.balance; } }; std::string genS(std::string s) { std::vector<ELEMENT> ss(s.size()); ss[0].c = s[0]; for (int i = 1; i < s.size(); i++) { ss[i].c = s[i]; ss[i].id = i; ss[i].balance = ss[i - 1].balance + 1 - 2 * (s[i - 1] == ')'); } std::sort(ss.begin(), ss.end()); std::string S; for (auto& i : ss) { S.push_back(i.c); } return S; } int main(){ std::string s; std::cin >> s; std::string s2 = genS(s), s3; while (s2 != s) { s3 = s2; s2 = genS(s2); } std::cout << s3 << '\n'; }
1970A2
wrong_submission
easy
259,493,168
C++17 (GCC 7-32)
WRONG_ANSWER on test 4
#include<bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s; cin>>s; vector<tuple<int,int,char> > v; for(int i=0,c=0;i<s.length();i++) v.emplace_back(c,i,s[i]),c+=(s[i]=='('?1:-1); sort(v.begin(),v.end()); for(auto [x,y,z]:v)cout<<z; cout<<endl; return 0; }
1970A2
wrong_submission
easy
300,298,972
Python 3
WRONG_ANSWER on test 4
string = str(input()).strip() scores = {} current = 0 for i,v in enumerate(string): scores[i] = current if v == "(": current += 1 else: current -= 1 sorter = sorted(scores,key=lambda a: (scores[a],a)) for i in sorter: print(string[i],end="")
1970A2
wrong_submission
easy
259,697,571
Python 3
WRONG_ANSWER on test 4
s = input() n = len(s) SUM = [0] * n for i in range(1, n): SUM[i] = SUM[i - 1] + (1 if s[i - 1] == '(' else -1) print(*map(lambda x: x[1], sorted(zip(SUM, s), key=lambda x: x[0])), sep='')
1970A2
wrong_submission
easy
259,496,515
Python 3
WRONG_ANSWER on test 4
s=input() t = s.split(')') ans = [t[0]] index = len(ans) for c in t[1:]: count = len(c) if not count: ans[index-1] += ')' else: ans[index-1] += '(' ans.insert(index, ')') for _ in range(count-1): ans.insert(index, '(') index -= 1 if not index: index = len(ans) - 1 print(''.join(ans))
1970A2
wrong_submission
easy
262,246,109
Java 21
WRONG_ANSWER on test 4
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws IOException { int t = 1; //t = f.nextInt(); while (t > 0) { solve(); t--; } w.flush(); w.close(); } static int mod = 998244353; static long inf = (long) 1e18; // 求区间第 public static void solve() throws IOException { char[] s = f.next().toCharArray(); int n = s.length; int p = 0; while(p < n){ if (s[p] == ')' && p + 1 < n && s[p+1] == '('){ s[p] = '('; s[p+1] = ')'; p+=2; }else p++; } for (int i = 0; i < n; i++) { w.print(s[i]); } } static class Pair{ int f, num; public Pair(int f, int num) { this.f = f; this.num = num; } } static long g(long x, long cur) { if (cur == 1) return 0; if (x % 2 == 0) { return g(x / 2, cur / 2); } else { return cur / 2 + g(x / 2, cur / 2); } } static int gcd(int a, int b) { if (a == 0) return b; if (b == 0) return a; return gcd(b, a % b); } static long qkm(long a, long b) { long res = 1; while (b > 0) { if ((b & 1) == 1) res = res * a; a = a * a; b >>= 1; } return res; } static long qkm(long a, long b, long mod) { long res = 1; while (b > 0) { if ((b & 1) == 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res; } public static class Node { char s; int id; int t; public Node(char s, int id, int t) { this.s = s; this.id = id; this. t = t; } public Node() { } } static boolean nextPermutation(int[] arr) { // 排列数循环模板 记得使用 do while 循环 int len = arr.length; int left = len - 2; while (left >= 0 && arr[left] >= arr[left + 1]) left--; // 从升序 一直往降序排列。 if (left < 0) return false; int right = len - 1; // 找到第一个升序的位置,将其改为降序。 while (arr[left] >= arr[right]) right--; { int t = arr[left]; arr[left] = arr[right]; arr[right] = t; } // 修改后它的前面仍然为降序,将前面全部修改为升序,这样能保证不会漏算,也不会算重 left++; right = len - 1; while (left < right) { { int t = arr[left]; arr[left] = arr[right]; arr[right] = t; } left++; right--; } // System.out.println(Arrays.toString(arr)); return true; } static PrintWriter w = new PrintWriter(new OutputStreamWriter(System.out)); static Input f = new Input(System.in); static class Input { public BufferedReader reader; public StringTokenizer tokenizer; public Input(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() throws IOException { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } return tokenizer.nextToken(); } public String nextLine() throws IOException { String str = null; str = reader.readLine(); return str; } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public Double nextDouble() throws IOException { return Double.parseDouble(next()); } } }
1970A2
wrong_submission
easy
259,495,649
Java 21
WRONG_ANSWER on test 4
import java.util.Scanner; public class balanced_shuffle_2 { public static String output(String s) { StringBuilder[] groups = new StringBuilder[s.length() + 1]; int balance = 0; for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (groups[balance] == null) groups[balance] = new StringBuilder(); groups[balance].append(c); if (c == '(') balance++; else balance--; } StringBuilder result = new StringBuilder(); for (StringBuilder group : groups) { if (group != null) result.append(group); } return result.toString(); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); String q = sc.next(); System.out.println(output(q)); } }
1970A2
wrong_submission
easy
259,494,588
C++17 (GCC 7-32)
TIME_LIMIT_EXCEEDED on test 8
#include <bits/stdc++.h> #define fi first #define se second #define int long long using namespace std; typedef pair<int, int> PII; typedef pair<int, char> PIC; typedef long long LL; string check(string s) { int n = s.size() - 1; std::vector<PII> tmp; int cnt = 0; for (int i = 1; i <= n; i ++) { tmp.emplace_back(cnt, i); if (s[i] == '(') cnt ++; else cnt --; } sort(tmp.begin(), tmp.end(), [&](PII a, PII b) { if (a.fi == b.fi) return a.se > b.se; return a.fi < b.fi; }); string res = " "; for (auto v : tmp) res += s[v.se]; return res; } signed main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(0); string s; cin >> s; int n = s.size(); s = ' ' + s; string t = check(s); while (check(t) != s) { t = check(t); } t.erase(0, 1); cout << t << endl; return 0; }
1970A2
wrong_submission
medium
263,086,564
C++17 (GCC 7-32)
WRONG_ANSWER on test 8
#include <bits/stdc++.h> using namespace std; bool sortbysec(const pair<long long, long long> &a, const pair<long long, long long> &b) { return (a.second < b.second); } void solve() { string s; cin >> s; vector<pair<long long, long long>> v; long long PB = 0; for (long long i = 0; i < s.size(); i++) { if (s[i] == '(') { v.push_back({PB, i + 1}); PB++; } else { v.push_back({PB, i + 1}); PB--; } } sort(v.begin(), v.end()); // for(auto i : v) cout<<i.first<<" "<<i.second<<endl; vector<int> count; vector<int> v1; vector<int> v2; int cou = 1; for(int i = 0;i<v.size();i++){ if(v[i].first != v[i+1].first){ count.push_back(cou); cou = 1; } else{ cou++; } } // v1.push_back(0); int x = 0; v1.push_back(0); for(int i = 0;i<count.size();i++){ x = x + count[i]; v1.push_back(x); } // for(auto i : v1) cout<<i<<" "; // cout<<endl; int a = v1[0]; int b = v1[1]-1; int k = 0; int i = 0; while(a<=b){ v2.push_back(v[b - i].second); i++; if(a >= b){ k++; a = v1[k] -1; b = v1[k+1]-1; i = 0; } a++; } // for(int i = 0;i<v2.size();i++){ // cout<<v2[i]<<" "; // } // cout<<endl; for(auto i : v2){ cout<<s[i - 1]; } } int main() { solve(); return 0; }
1970A2
wrong_submission
medium
260,406,863
Python 3
WRONG_ANSWER on test 8
def balanced_unshuffle(s): # Initialize a list to store tuples of character, position, and prefix balance seq = [(s[i], i, s[:i].count('(') - s[:i].count(')')) for i in range(len(s))] # Sort the list of tuples based on prefix balance in increasing order, # breaking ties by position in decreasing order sorted_seq = sorted(seq, key=lambda x: (x[2], -x[1])) # Extract the characters from the sorted list of tuples preimage = ''.join([char for char, _, _ in sorted_seq]) return preimage if __name__ == "__main__": s = input().strip() preimage = balanced_unshuffle(s) print(preimage)
1970A2
wrong_submission
medium
259,951,575
Python 3
WRONG_ANSWER on test 8
def balanced_shuffle(s): n = len(s) # Prepare list to hold the prefix balance, position, and character entries = [] # Calculate prefix balances balance = 0 for i, char in enumerate(s): if char == '(': balance += 1 else: # char == ')' balance -= 1 # Append the current balance AFTER this character, position, and the character itself entries.append((balance, i, char)) # Adjust balance values to reflect the state before the character for i in range(len(entries)): if entries[i][2] == ')': entries[i] = (entries[i][0] + 1, entries[i][1], entries[i][2]) else: entries[i] = (entries[i][0] - 1, entries[i][1], entries[i][2]) # Sort entries by balance (increasing) and by position (decreasing) entries.sort(key=lambda x: (x[0], -x[1])) # Build the result using the character from sorted entries result = ''.join(entry[2] for entry in entries) return result def main(): # Read input from standard input input_sequence = input().strip() # Get the balanced shuffle output output_sequence = balanced_shuffle(input_sequence) # Output result to standard output print(output_sequence) if __name__ == "__main__": main()
1970A2
wrong_submission
medium
302,463,306
Java 21
WRONG_ANSWER on test 8
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String s=sc.nextLine(); int []a=new int[s.length()]; Map<Integer,List<Integer>>mp=new HashMap<>(); //to store balance factor: corresponding indices of array a[0]=0; //1st element int i=1; char[]ch=s.toCharArray(); //for calculating balance factor List<Integer>first=new ArrayList<>(); //to add 1st ele into map first.add(0); mp.put(0,first); for(int j=1;j<s.length();j++) { if(ch[j-1]=='(') //calculating balance factor each index { a[i]=a[i-1]+1; } else { a[i]=a[i-1]-1; } mp.putIfAbsent(a[i], new ArrayList<>()); // map: ( bf : index list ) mp.get(a[i]).add(i); //for eg: 1 2 3 index has bf as 5 map looks like (5:1,2,3) i++; } Arrays.sort(a); //sorting bf as asc order Set<Integer>st=new HashSet<>(); // to avoid repetition of bf as we are adding every char of balance factor at once in line 41-44 for(int l:a) { if(!st.contains(l)) // if bf occurs 1st time we print all indices of it so need to iterate on same bf again { List<Integer>ele=mp.get(l); //extracting list of indices Collections.reverse(ele); // as given in the que, indices should be in desc order st.add(l); //adding into set to avoid iterating on same bf again for(int ele2:ele) { System.out.print(s.charAt(ele2)); // printing char at indices } } } } }
1970A2
wrong_submission
medium
301,657,187
Java 21
WRONG_ANSWER on test 8
import java.io.*; import java.util.*; public class BalancedUnshuffle { public static void main(String[] args) throws Exception { // TODO Auto-generated method stub BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s = br.readLine(); int[][] a = new int[s.length()][3]; for(int j=0; j<s.length(); j++) { if(s.charAt(j)=='(') a[j][0] = 1; else a[j][0] = -1; a[j][2] = j; if(j!=0) a[j][1] = a[j-1][1]+a[j-1][0]; } Arrays.sort(a, (p,q) -> p[1]!=q[1] ? p[1]-q[1] : q[2]-p[2]); for(int j=0; j<s.length(); j++) { if(a[j][0]==1) System.out.print("("); else System.out.print(")"); } } }
1970A2
wrong_submission
medium
262,005,696
C++17 (GCC 7-32)
WRONG_ANSWER on test 8
#include<bits/stdc++.h> using namespace std; struct Shuffle { int balance; int p; char c; }; bool cmp(Shuffle a,Shuffle b) { if(a.balance==b.balance) return a.p>b.p; else return a.balance<b.balance; } int main() { vector<Shuffle> v; string s; cin>>s; int n=0; for(int i=0;i<s.size();i++) { v.push_back({n,i,s[i]}); if(s[i]=='(') n++; else n--; } sort(v.begin(),v.end(),cmp); for(int i=0;i<v.size();i++) { cout<<v[i].c; } return 0; }
1970A2
wrong_submission
hard
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
20