Post

Replies

Boosts

Views

Activity

Reply to Xcode 14 update has bugs and my code in c++ is not compiling with memory issues.
Here is the simplified version of above code with the same issue:- #include<iostream> #include<vector> #include<map> using namespace std; const int inf = 2e9; int nu(vector<int>& suff, int l, int r, int n){ int ans = suff[l] - (r<n?suff[r+1]:0); return ans%9; } void test_case() { string s; cin>>s; int n = s.size(); int w, m; cin>>w>>m; vector<int> suff(n+1,0); suff[n] = (s[n-1]-'0'); for(int i = n-2;i>=0;i--){ suff[i+1] = suff[i+2] + (s[i]-'0'); } map<int, pair<int, int>> mp; for(int i = n-w+1;i>0;i--){ int t= nu(suff, i, i+w-1, n); mp[t] = {i, mp[t].first}; } while(m--){ int l,r,k; cin>>l>>r>>k; int v = nu(suff, l, r, n); int ans1 = inf, ans2 = inf; for(int j = 0;j<9;j++){ int l1 = mp[j].first; int p = (j*v)%9; int x = (k-p+9)%9; int l2 = mp[x].first; if(l2==l1) l2 = mp[x].second; if(l1>0 and l2>0){ if(l1<ans1){ ans1 = l1; ans2 = l2; }else if(l1==ans1){ ans2 = min(ans2, l2); } } } if(ans1<inf and ans2<inf){ cout<<ans1<<" "<<ans2<<endl; }else cout<<"-1 -1"<<endl; } } int main() { int tt = 1; cin >> tt; for(int i = 1;i<=tt;i++) { test_case(); } return 0; }
Sep ’22
Reply to Xcode 14 update has bugs and my code in c++ is not compiling with memory issues.
If you are trying to run this code and #include<bits/stdc++.h> is not working on your system, replace it with #include<iostream> #include<vector> #include<map> Then you check for compilation issue.
Replies
Boosts
Views
Activity
Sep ’22
Reply to Xcode 14 update has bugs and my code in c++ is not compiling with memory issues.
@eskimo Please update your macOS and try again.
Replies
Boosts
Views
Activity
Sep ’22
Reply to Xcode 14 update has bugs and my code in c++ is not compiling with memory issues.
I have tried different codes, they are also not working (not all codes have this issue). I confirmed it with my friends and they are also getting the same problem after update.
Replies
Boosts
Views
Activity
Sep ’22
Reply to Xcode 14 update has bugs and my code in c++ is not compiling with memory issues.
Here is the simplified version of above code with the same issue:- #include<iostream> #include<vector> #include<map> using namespace std; const int inf = 2e9; int nu(vector<int>& suff, int l, int r, int n){ int ans = suff[l] - (r<n?suff[r+1]:0); return ans%9; } void test_case() { string s; cin>>s; int n = s.size(); int w, m; cin>>w>>m; vector<int> suff(n+1,0); suff[n] = (s[n-1]-'0'); for(int i = n-2;i>=0;i--){ suff[i+1] = suff[i+2] + (s[i]-'0'); } map<int, pair<int, int>> mp; for(int i = n-w+1;i>0;i--){ int t= nu(suff, i, i+w-1, n); mp[t] = {i, mp[t].first}; } while(m--){ int l,r,k; cin>>l>>r>>k; int v = nu(suff, l, r, n); int ans1 = inf, ans2 = inf; for(int j = 0;j<9;j++){ int l1 = mp[j].first; int p = (j*v)%9; int x = (k-p+9)%9; int l2 = mp[x].first; if(l2==l1) l2 = mp[x].second; if(l1>0 and l2>0){ if(l1<ans1){ ans1 = l1; ans2 = l2; }else if(l1==ans1){ ans2 = min(ans2, l2); } } } if(ans1<inf and ans2<inf){ cout<<ans1<<" "<<ans2<<endl; }else cout<<"-1 -1"<<endl; } } int main() { int tt = 1; cin >> tt; for(int i = 1;i<=tt;i++) { test_case(); } return 0; }
Replies
Boosts
Views
Activity
Sep ’22
Reply to Xcode 14 update has bugs and my code in c++ is not compiling with memory issues.
@endecotp Please compile the newer version of code anywhere other than Xcode. MacOS version does not matter. XCode version should be 14.0.0.
Replies
Boosts
Views
Activity
Sep ’22
Reply to Xcode 14 update has bugs and my code in c++ is not compiling with memory issues.
@endecotp I am compiling code using gnu compiler instead of clang compiler. On clang it is compiling perfectly but on gnu it is not. By default I am using gnu compiler.
Replies
Boosts
Views
Activity
Sep ’22