Common BoardI cant understand my mistake for TLE14. My code var s,s1,s2: string; z2,z1,a,i,f,p,code: integer;z,n:int64; ch:char; begin readln(s); readln(npalindrome? 1 100000); for i:=1 to n do begin readln(s2); if s2[1]='p' then begin a:=13;z1:=0;z2:=0; while s2[a]<>' ' do inc(a); val(copy(s2,13,a-13),z1,code); val(copy(s2,a+1,length(s2)-1),z2,code); z:=z2-z1+1; if z2>length(s) then z2:=length(s); s1:=copy(s,z1,z);
f := 1; p:=1; while (p<=length(s1)div 2)and(f<>0) do if (s1[p] <> s1[length(s1)-p+1]) then begin writeln('No'); f := 0; end else p:=p+1;
if f = 1 then writeln('Yes'); end else begin a:=8;z1:=0; while s2[a]<>' ' do inc(a); Val(copy(s2,8,a-8),z1,code); ch:=s2[a+1]; delete(s,z1,1); insert(ch,s,z1);
end; end; end. Check that arrays were initiated with zeroes. unfortunately it didn't help. //#pragma GCC optimize("Ofast,no-stack-protector") //#pragma GCC target("avx") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds; using namespace std;
#define re return #define pb push_back #define eb emplace_back #define all(x) (x).begin(), (x).end() #define fi first #define se second #define sqrt(x) sqrt(abs(x)) #define mp make_pair #define pi (3.14159265358979323846264338327950288419716939937510) #define fo(i, n) for(int i = 0; i < n; ++i) #define ro(i, n) for(int i = n - 1; i >= 0; --i) #define unique(v) v.resize(unique(all(v)) - v.begin())
template <class T> T abs (T x) { re x > 0 ? x : -x; } template <class T> T sqr (T x) { re x * x; } template <class T> T gcd (T a, T b) { re a ? gcd (b % a, a) : b; } template <class T> int sgn (T x) { re x > 0 ? 1 : (x < 0 ? -1 : 0); }
typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<string> vs; typedef double D; typedef long double ld; typedef long long ll; typedef pair<ll, ll> pll; typedef vector<ll> vll; typedef unsigned long long ull; typedef tree <pair<int, char>, null_type, less<pair<int, char>>, rb_tree_tag, tree_order_statistics_node_update> _tree; const int maxn = (int) 1e5; int a[maxn]; int main() { int n, x; cin >> n; fo(i, n) { cin >> a[i]; } sort(a, a + n); string str; cin >> str >> n; fo(i, n) { cin >> x; cout << a[x - 1] << '\n'; } re 0; } package timusreverseroot; import java.text.DecimalFormat; import java.util.*; public class TimusReverseRoot { public static void main(String[] args) { DecimalFormat f = new DecimalFormat("#0.0000"); Scanner keyboard = new Scanner(System.in); String inputs = keyboard.nextLine(); String[] parsed = inputs.split(" ");
for (String parsed1 : parsed) { int square = (int) Math.pow(Integer.parseInt(parsed1), 2); System.out.println(f.format(square)); } }
} I added in the package line but if I left that in, it would give me a compilation error, why is that? And this code runs perfectly fine in Netbeans but the judge gives a compilation error Edited by author 07.05.2018 22:48 Edited by author 07.05.2018 22:49 Edited by author 07.06.2018 01:49 //#pragma GCC optimize("Ofast,no-stack-protector") //#pragma GCC target("avx") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds; using namespace std;
#define re return #define pb push_back #define eb emplace_back #define all(x) (x).begin(), (x).end() #define fi first #define se second #define sqrt(x) sqrt(abs(x)) #define mp make_pair #define pi (3.14159265358979323846264338327950288419716939937510) #define fo(i, n) for(int i = 0; i < n; ++i) #define ro(i, n) for(int i = n - 1; i >= 0; --i) #define unique(v) v.resize(unique(all(v)) - v.begin())
template <class T> T abs (T x) { re x > 0 ? x : -x; } template <class T> T sqr (T x) { re x * x; } template <class T> T gcd (T a, T b) { re a ? gcd (b % a, a) : b; } template <class T> int sgn (T x) { re x > 0 ? 1 : (x < 0 ? -1 : 0); }
typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<string> vs; typedef double D; typedef long double ld; typedef long long ll; typedef pair<ll, ll> pll; typedef vector<ll> vll; typedef unsigned long long ull; typedef tree <pair<int, char>, null_type, less<pair<int, char>>, rb_tree_tag, tree_order_statistics_node_update> _tree; int main() { int n, x; ii ans = mp(-1, 0); pair <ii, int> cur; cin >> n >> cur.fi.fi; cur.fi.se = cur.se = 0; fo(i, n - 1) { cin >> x; if (x >= cur.fi.fi) ++cur.fi.se; else { cur.fi.se++; ans = max(ans, mp(cur.fi.se, cur.se)); cur = mp(mp(x, 1), i + 1); } } ans = max(ans, mp(cur.fi.se, cur.se)); cout << ans.se + 1 << endl; } //#pragma GCC optimize("Ofast,no-stack-protector") //#pragma GCC target("avx") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds; using namespace std;
#define re return #define pb push_back #define eb emplace_back #define all(x) (x).begin(), (x).end() #define fi first #define se second #define sqrt(x) sqrt(abs(x)) #define mp make_pair #define pi (3.14159265358979323846264338327950288419716939937510) #define fo(i, n) for(int i = 0; i < n; ++i) #define ro(i, n) for(int i = n - 1; i >= 0; --i) #define unique(v) v.resize(unique(all(v)) - v.begin())
template <class T> T abs (T x) { re x > 0 ? x : -x; } template <class T> T sqr (T x) { re x * x; } template <class T> T gcd (T a, T b) { re a ? gcd (b % a, a) : b; } template <class T> int sgn (T x) { re x > 0 ? 1 : (x < 0 ? -1 : 0); }
typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<string> vs; typedef double D; typedef long double ld; typedef long long ll; typedef pair<ll, ll> pll; typedef vector<ll> vll; typedef unsigned long long ull; typedef tree <pair<int, char>, null_type, less<pair<int, char>>, rb_tree_tag, tree_order_statistics_node_update> _tree; double calc () { int a, b; cin >> a >> b; if (a == 1) re b * 2; if (a == 2) re b; re sqrt(3) * b / 2.0; } int main() { int ans = 0, a, b; double fuck; cin >> a >> b; if (a == 1) fuck = b * 2; if (a == 2) fuck = b * sqrt(2); if (a == 3) fuck = b; int n; cin >> n; fo(i, n) { if (calc() <= fuck) ++ans; } cout << ans << endl; } //#pragma GCC optimize("Ofast,no-stack-protector") //#pragma GCC target("avx") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds; using namespace std;
#define re return #define pb push_back #define eb emplace_back #define all(x) (x).begin(), (x).end() #define fi first #define se second #define sqrt(x) sqrt(abs(x)) #define mp make_pair #define pi (3.14159265358979323846264338327950288419716939937510) #define fo(i, n) for(int i = 0; i < n; ++i) #define ro(i, n) for(int i = n - 1; i >= 0; --i) #define unique(v) v.resize(unique(all(v)) - v.begin())
template <class T> T abs (T x) { re x > 0 ? x : -x; } template <class T> T sqr (T x) { re x * x; } template <class T> T gcd (T a, T b) { re a ? gcd (b % a, a) : b; } template <class T> int sgn (T x) { re x > 0 ? 1 : (x < 0 ? -1 : 0); }
typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<string> vs; typedef double D; typedef long double ld; typedef long long ll; typedef pair<ll, ll> pll; typedef vector<ll> vll; typedef unsigned long long ull; typedef tree <pair<int, char>, null_type, less<pair<int, char>>, rb_tree_tag, tree_order_statistics_node_update> _tree; int main() { int n; cin >> n; vector <pair<ii, int>> v(n); fo(i, n) { cin >> v[i].fi.fi >> v[i].fi.se; v[i].se = i + 1; } sort(all(v)); for (int i = 0; i < n; i += 2) { cout << v[i].se << ' '<< v[i + 1].se << '\n'; } } I have got error so many times. Wonder wht I am missing.. Here is my Python 3.4 Code n,m=map(int,input().split()) g=list(map(int,input().split())) b=list(map(int,input().split())) g.sort() b.sort() minUpset=0 for i in range(0,n): minUpset+=g[i] for s in range(0,min(n,m)): girlsUpset=0 boysUpset=0 for i in range(0,n-s): girlsUpset+=g[i] for j in range(0,m-s): boysUpset+=b[j] minUpset=min(girlsUpset+boysUpset*s,minUpset) print(minUpset)
Found the mistake. Always need to test when use loop. for s in range(0, min(n, m) + 1) //#pragma GCC optimize("Ofast,no-stack-protector") //#pragma GCC target("avx") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds; using namespace std;
#define re return #define pb push_back #define eb emplace_back #define all(x) (x).begin(), (x).end() #define fi first #define se second #define sqrt(x) sqrt(abs(x)) #define mp make_pair #define pi (3.14159265358979323846264338327950288419716939937510) #define fo(i, n) for(int i = 0; i < n; ++i) #define ro(i, n) for(int i = n - 1; i >= 0; --i) #define unique(v) v.resize(unique(all(v)) - v.begin())
template <class T> T abs (T x) { re x > 0 ? x : -x; } template <class T> T sqr (T x) { re x * x; } template <class T> T gcd (T a, T b) { re a ? gcd (b % a, a) : b; } template <class T> int sgn (T x) { re x > 0 ? 1 : (x < 0 ? -1 : 0); }
typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<string> vs; typedef double D; typedef long double ld; typedef long long ll; typedef pair<ll, ll> pll; typedef vector<ll> vll; typedef unsigned long long ull; typedef tree <pair<int, char>, null_type, less<pair<int, char>>, rb_tree_tag, tree_order_statistics_node_update> _tree; const int maxn = 100; int a[maxn], b[maxn]; int main() { int n, m; cin >> n >> m; fo(i, n) cin >> a[i]; fo(i, m) cin >> b[i]; sort(a, a + n), sort(b, b + m); reverse(a, a + n), reverse(b, b + m); int ans = (int) 1e9, cur; fo(k, min(n, m) + 1) { cur = 0; for (int j = k; j < n; ++j) cur += a[j]; for (int j = k; j < m; ++j) cur += b[j] * k; ans = min (ans, cur); } cout << ans << endl; } //#pragma GCC optimize("Ofast,no-stack-protector") //#pragma GCC target("avx") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds; using namespace std;
#define re return #define pb push_back #define eb emplace_back #define all(x) (x).begin(), (x).end() #define fi first #define se second #define sqrt(x) sqrt(abs(x)) #define mp make_pair #define pi (3.14159265358979323846264338327950288419716939937510) #define fo(i, n) for(int i = 0; i < n; ++i) #define ro(i, n) for(int i = n - 1; i >= 0; --i) #define unique(v) v.resize(unique(all(v)) - v.begin())
template <class T> T abs (T x) { re x > 0 ? x : -x; } template <class T> T sqr (T x) { re x * x; } template <class T> T gcd (T a, T b) { re a ? gcd (b % a, a) : b; } template <class T> int sgn (T x) { re x > 0 ? 1 : (x < 0 ? -1 : 0); }
typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<string> vs; typedef double D; typedef long double ld; typedef long long ll; typedef pair<ll, ll> pll; typedef vector<ll> vll; typedef unsigned long long ull; typedef tree <pair<int, char>, null_type, less<pair<int, char>>, rb_tree_tag, tree_order_statistics_node_update> _tree; int calc () { string str; cin >> str; re (str[0] - '0') * 600 + (str[1] - '0') * 60 + stoi(str.substr(3, 2)); } int main() { int n1, n2, n3, c1, c2, t; cin >> n1 >> c1 >> n2 >> t >> c2 >> n3; int k, time; int ans = 0; cin >> k; while (k--) { time = calc(); if (time <= 6) continue; ans += (time + 59) / 60; } cout << "Basic: " << n1 + ans * c1 << endl; cout << "Combined: " << n2 + max(0, ans - t) * c2 << endl; cout << "Unlimited: " << n3 << endl; } n=100: 168 n=555: 984 n=1000: 1785 n=1100: 1963 n=2000: 3598 I solved the equation x(x-1) % 10^i = 0 for every i>1 and i<=n by linear algorithm, using roots for i-1. Test 2 is something like this 3 2 0 Good luck! Thank you very very much , I love u Thank you !!! you test help found my mistake i tested the answer is 500. it's right. but i still get WA 2 Use if(c> 8000000000LL || c< -8000000000LL) break ; this line in BInary search... code : [deleted] Edited by author 01.06.2018 17:02 Edited by moderator 20.11.2019 22:45 plz can someone give the 4th test Try the case when total time is less than prepayed time in 'Combined' rate. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp4 { class Program { static void Main(string[] args) { int n = Convert.ToInt16(Console.ReadLine()); int s = 2; for (int i = 1; i<=n; i++) { string a = Console.ReadLine(); if (a.Contains("+one")) s += 2; else s++; } if (s == 13) s++; Console.WriteLine(s * 100); } } } Did anybody get AC with the MaxFlow algorithm? Sure, why not? Push relabel algorithm got TL on test 30. Dinic with scaling got AC in 0.249 s. Interestingly, push-relabel algorithm (with some optimizations) that I used is usually a little bit faster than my Dinic with scaling. 4 2 3 2 11. . 2 3 0 10, 4 3 0 19. . Answer: Impossible Source: AC program 4 2 0 0 47, 3 17 17 25, 4 0 0 38. 1 17 17 31, 3 0 0 23, 4 0 0 96. 1 0 0 96, 2 0 0 48, 4 17 17 91. . = 69 2 0, 3 17, 4 1. 1 18, 3 0, 4 0. 1 0, 2 0, 4 17. . 8 . 1 0 0 39, 5 13 13 21. 5 0 0 87, 8 41 41 92. 5 38 38 85. 6 41 41 14, 8 10 10 49. 2 10 10 69, 3 41 41 58, 4 0 0 73. 6 3 3 59. . = 49 . 1 0, 5 13. 5 0, 8 41. 5 38. 6 40, 8 11. 2 10, 3 41, 4 0. 6 3. . Edited by author 16.06.2008 04:40 Why not 4 2 0 0 47, 3 17 17 25, 4 0 0 38. 1 17 17 31, 3 0 0 23, 4 0 0 96. 1 0 0 96, 2 0 0 48, 4 17 17 91. . = 61 2 0, 3 16, 4 1. 1 17, 3 1, 4 0. 1 0, 2 0, 4 17. . For those confused by this test case. I believe svr's answer is right as my AC program outputs this very result. Slobodan has AC as well though. //#pragma GCC optimize("Ofast,no-stack-protector") //#pragma GCC target("avx") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds; using namespace std;
#define re return #define pb push_back #define eb emplace_back #define all(x) (x).begin(), (x).end() #define fi first #define se second #define sqrt(x) sqrt(abs(x)) #define mp make_pair #define pi (3.14159265358979323846264338327950288419716939937510) #define fo(i, n) for(int i = 0; i < n; ++i) #define ro(i, n) for(int i = n - 1; i >= 0; --i) #define unique(v) v.resize(unique(all(v)) - v.begin())
template <class T> T abs (T x) { re x > 0 ? x : -x; } template <class T> T sqr (T x) { re x * x; } template <class T> T gcd (T a, T b) { re a ? gcd (b % a, a) : b; } template <class T> int sgn (T x) { re x > 0 ? 1 : (x < 0 ? -1 : 0); }
typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<string> vs; typedef double D; typedef long double ld; typedef long long ll; typedef pair<ll, ll> pll; typedef vector<ll> vll; typedef unsigned long long ull; typedef tree <pair<int, char>, null_type, less<pair<int, char>>, rb_tree_tag, tree_order_statistics_node_update> _tree; const int maxn = 5; int sz[2][maxn]; bool how[maxn]; int pos1[maxn], pos2[maxn]; bool check_intersection () { bool check = true; fo(i, 5) { fo(j, i) { check = false; if (pos1[i] + sz[how[i]][i] <= pos1[j]) check = true; if (pos1[j] + sz[how[j]][j] <= pos1[i]) check = true; if (pos2[i] + sz[!how[i]][i] <= pos2[j]) check = true; if (pos2[j] + sz[!how[j]][j] <= pos2[i]) check = true; if (!check) re false; } } re true; } bool check_area () { int x = -1, y = -1; fo(i, 5) { x = max(x, pos1[i] + sz[how[i]][i]); y = max(y, pos2[i] + sz[!how[i]][i]); } int s1 = 0, s2 = x * y; fo(i, 5) s1 += sz[0][i] * sz[1][i]; re s1 == s2; } bool major_check() { bool ans = check_area() && check_intersection(); re ans; }
vector <pair <ii, bool> > v; bool f (int mask) { if (__builtin_popcount(mask) == 5) re major_check(); fo(a, 5) { if (((1 << a) & mask) == 0) { fo(q, 2) { how[a] = q; fo(i, v.size()) { if (v[i].se) continue; ii j = v[i].fi; v[i].se = true; v.pb(mp(mp(j.fi + sz[how[a]][a], j.se), false)); v.pb(mp(mp(j.fi, j.se + sz[!how[a]][a]), false)); pos1[a] = j.fi; pos2[a] = j.se; if (f(mask | (1 << a))) re true; v[i].se = false; v.pop_back(); v.pop_back(); } } } } re false; } int main() { fo(i, 5) fo(j, 2) cin >> sz[j][i]; v.eb(mp(0, 0), 0); if (f(0)) cout << "YES" << endl; else cout << "NO" << endl; } |
|