id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "class Solution {\npublic:\n\n\nbool isDivisible(string num, int k)\n{\n int len = num.length();\n if (len == 1)\n {\n return (num[0] - '0') % k == 0;\n }\n if (k == 1)\n {\n return true;\n }\n if (k == 2)\n {\n int x = (num[len - 1] - '0');\n return x ...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "class Solution {\npublic:\n\n\nbool isDivisible(string num, int k)\n{\n int len = num.length();\n if (len == 1)\n {\n return (num[0] - '0') % k == 0;\n }\n if (k == 1)\n {\n return true;\n }\n if (k == 2)\n {\n int x = (num[len - 1] - '0');\n return x ...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "class Solution {\npublic:\n vector<string> generate(long long min,long long max,int digits){\n vector<string> answer;\n for(long long i = min;i <= max;i++){\n string temp;\n if(!(digits%2)){\n temp = to_string(i);\n reverse(temp.begin(),t...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "class Solution {\npublic:\n vector<string> generate(long long min,long long max,int digits){\n vector<string> answer;\n for(long long i = min;i <= max;i++){\n string temp;\n if(!(digits%2)){\n temp = to_string(i);\n reverse(temp.begin(),t...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "class Solution {\npublic:\n vector<string> ps; \n void generatePalindromes(string & curr, int ind, bool flg = true) {\n int n = curr.size(); \n\n if (ind >= (n + 1) / 2) {\n ps.push_back(curr); \n return; \n }\n\n char start = flg ? '1' : '0'; \n\n ...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "class Solution {\npublic:\n vector<string> ps; \n void generatePalindromes(string & curr, int ind, bool flg = true) {\n int n = curr.size(); \n\n if (ind >= (n + 1) / 2) {\n ps.push_back(curr); \n return; \n }\n\n char start = flg ? '1' : '0'; \n\n ...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "#define ll long long\n\nclass Solution {\npublic:\n\nll vectorToNumber(vector<int>& num) {\n ll ans = 0;\n for (int digit : num) {\n ans = ans * 10 + digit;\n }\n return ans;\n }\n\n ll fact(int n){\n ll ans = 1;\n for(int i=2 ; i<=n ; i++) ans *= ...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "class Solution {\npublic:\n long long findPermutations(map<int,int>& hash, int n, vector<int>& factorial) {\n long long permutations = factorial[n];\n for (auto itr : hash) {\n permutations /= factorial[itr.second];\n }\n return permutations;\n }\n\n long lon...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "#include <iostream>\n#include <vector>\n#include <unordered_map>\n#include <string>\nusing namespace std;\n\ntypedef long long ll;\n\nclass Solution {\nprivate:\n // Helper function to generate palindromic numbers of given length\n \n\n // Function to convert string to number\n ll convert(const ...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "class Solution {\npublic:\n vector<string> palin;\n long long int getInt(string s){\n long long int ans=0;\n for(int i=0;i<s.length();i++){\n ans=(ans*10)+(s[i]-'0');\n }\n return ans;\n }\n map<long long int,long long int> fact;\n void generatePalin(int i,int n,string curr){\n ...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "using ll = long long;\nll fact[11];\n\nclass Solution {\npublic:\n\n int tot;\n ll calc(vector<int> f)\n {\n ll ans = 0;\n // fix first pos\n for (int i=1; i<=9; i++)\n {\n if (f[i])\n {\n f[i]--;\n ll cur = fact[tot-1...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "class Solution {\npublic:\n int order(int n, int a){\n vector<int> aDigs(n, 0);\n for(int i=0; i<(n+1)/2; ++i){\n aDigs[i] = a%10;\n aDigs[n-1-i] = a%10;\n a /= 10;\n }\n sort(aDigs.begin(), aDigs.end());\n long long ans = 0;\n f...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "class Solution {\n set<map<int,int>>visited;\n vector<int>factorial;\npublic:\n Solution(){\n ios_base :: sync_with_stdio(false);\n }\n void generateFactorial(){\n factorial.resize(11,1);\n int prod = 1;\n for(int i = 2;i<11;i++){\n prod *= i;\n ...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "class Solution {\npublic:\n #define X first\n #define Y second\n bool isdivisible(string &s, int k){\n long long mod = 0;\n for (char ch : s) {\n mod = (mod * 10 + (ch - '0')) % k;\n }\n return mod == 0;\n }\n \n \nlong long factorial(int n) {\n l...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "class Solution {\n long long vectorToNumber(const vector<int>& num) {\n long long ans = 0;\n for (int digit : num) {\n ans = ans * 10 + digit;\n }\n return ans;\n }\n\n long long fact(int n){\n long long ans = 1;\n for(int i=2 ; i<=n ; i++) ans ...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "class Solution {\npublic:\n long long ans=0;\n set<map<int,int>> vis;\n long long con(vector<int>&nums){\n long long b=0;\n for(int i=0;i<nums.size();i++){\n b=b*10+nums[i];\n }\n return b;\n }\n long long fact(int x){\n long long f=1;\n f...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "class Solution {\npublic:\n long long fact(int n){\n long long ans=1;\n for(int i=1;i<=n;i++) ans=ans*i;\n return ans;\n }\n long long countGoodIntegers(int n, int k) {\n vector<int> num;\n long long fac[12]={0};\n for(int i=0;i<12;i++) fac[i]=fact(i);\n ...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "class Solution {\npublic:\n long long fact(int n){\n long long ans=1;\n for(int i=1;i<=n;i++) ans=ans*i;\n return ans;\n }\n long long countGoodIntegers(int n, int k) {\n vector<int> num;\n for(int i=1;i<=9;i++) num.push_back(i);\n int req=(n+1)/2;\n ...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "class Solution {\npublic:\n long long countGoodIntegers(int n, int k) {\n vector<string> perms = generatePemutations(n, true);\n\n long long answer = 0;\n\n std::unordered_set<std::vector<int>, VectorHash> st;\n\n for (string perm: perms) {\n long long p = stoll(pe...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "class Solution {\n#define append push_back\npublic:\nlong long fact(long long n){\n if (n == 0 || n == 1)\n return 1;\n return n * fact(n-1);\n}\n void solve(int index, int n, vector<string> &v, string &s){\n if (index==n) {v.append(s); return;}\n for(int i=0; i<10; i++){\n ...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "#include<bits/stdc++.h>\nusing namespace std;\n\nclass Solution {\n long long vectorToNumber(const vector<int>& num) {\n long long number = 0;\n for (int digit : num) {\n number = number * 10 + digit;\n }\n return number;\n }\n\n long long fact(int n){\n ...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "#include<bits/stdc++.h>\nusing namespace std;\n\nclass Solution {\n long long vectorToNumber(const vector<int>& num) {\n long long number = 0;\n for (int digit : num) {\n number = number * 10 + digit;\n }\n return number;\n }\n\n long long fact(int n){\n ...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "class Solution {\npublic:\n long long countGoodIntegers(int n, int k) {\n if (n == 1) {\n int ans = 0;\n for (int i = 1; i <= 9; i ++) {\n if (i % k == 0) {\n ans ++;\n }\n }\n return ans;\n }\n ...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "#include <bits/stdc++.h>\nusing namespace std;\n\nclass Solution {\n\tlong long vectorToNumber(const vector<int>& num) {\n\t\tlong long ans = 0;\n\t\tfor (int digit : num) {\n\t\t\tans = ans * 10 + digit;\n\t\t}\n\t\treturn ans;\n\t}\n\tlong long fact(int n) {\n\t\tlong long ans = 1;\n\t\tfor (int i = 2 ; ...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "#define ll long long\nclass Solution {\n set<map<int,int>>vis;\n ll ans;\n vector<ll>fact;\n void fct()\n {\n int n=fact.size();\n fact[0]=fact[1]=1;\n for(int i=2;i<n;i++)\n {\n fact[i]=fact[i-1]*i;\n }\n }\n ll tot(map<int,int>m)\n {\n...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "#pragma GCC optimize(\"O3,unroll-loops\")\n#include<bits/stdc++.h>\n// #include<ext/pb_ds/assoc_container.hpp>\n// #include<ext/pb_ds/tree_policy.hpp>\nusing namespace std;\nusing namespace chrono;\n// using namespace __gnu_pbds;\n// def\n//#define kundan1 1\n#define fastio() ios_base::sync_with_stdio(fals...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "#define ll long long\nclass Solution {\npublic:\n bool divisible(string &tmp, ll k)\n {\n ll n = stol(tmp);\n if (n % k == 0)\n {\n return true;\n }\n return false;\n }\n\n void recur(string &s, ll need, bool first, vector<string> & v, ll last = 0)\...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "class Solution {\npublic:\n set<string> s;\n set<map<char,int>> tt;\n void slove(int n,int k,int idx,string cur){\n if(idx==n/2){\n if(n%2==0){\n long tmp=stol(cur+string(cur.rbegin(),cur.rend()));\n if(tmp%k==0){\n s.insert(to_str...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "\nclass Solution {\n long long factorialArr[11];\n\n // Fake DFS function for demonstration\n void fakeDFS(int node, vector<int>& visited, vector<vector<int>>& adjList) {\n stack<int> dfsStack;\n dfsStack.push(node);\n visited[node] = 1;\n\n while (!dfsStack.empty()) {\...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "class Solution {\npublic:\n using ll=long long;\n ll p[11];\n ll jp[11];\n long long countGoodIntegers(int n, int k) {\n p[0]=1;\n jp[0]=1;\n for(int i=1;i<=10;i++) {\n p[i]=p[i-1]*10%k;\n jp[i]=jp[i-1]*10;\n }\n map<vector<ll>,ll> mp;\n ...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "#include <bits/stdc++.h>\nusing namespace std;\n\n#define lli long long\n#define endl '\\n'\n#define loop(i, n) for (int i = 0; i < n; i++)\n#define pool(i, n) for (int i = n - 1; i >= 0; i--)\n#define rep(i, a, b) for (int i = a; i <= b; i++)\n#define per(i, b, a) for (int i = b; i >= a; i--)\n#define all...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "class Solution {\npublic:\n typedef long long ll;\n vector<ll> allint;\n unordered_map<string,int> digitfreq;\n ll factorial(ll num)\n {\n ll ans = 1;\n for(ll i =1;i<=num;i++) ans*=i;\n return ans;\n }\n ll generateCombinations(int n, ll num, int k)\n {\n ...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "class Solution {\npublic:\n long long int n;\n long long int k;\n vector<long long int>factorials = {1,1,2,6,24,120,720,5040,40320,362880,3628800};\n long long int convertVectorToNumber(vector<long long int>&v)\n {\n long long int result = 0;\n for(long long int i=v.size()-1;i>...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "class Solution {\npublic:\n bool check(string s,int k){\n long long rem=0;\n for(char c:s){\n rem=(rem*10 + (c-'0'))%k;\n }\n return rem==0;\n }\n vector<long long> fact(long long n){\n vector<long long int> fac(n + 1);\n fac[0] = 1;\n fo...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "class Solution {\npublic:\n vector<vector<long long int>> P;\n void f()\n {\n P = vector<vector<long long int>>(11);\n vector<vector<string>> dummy(11);\n for(int i = 0; i < 10; i++)\n {\n string x;\n x.push_back('0'+i);\n dummy[1].push_...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "#define ll long long\nvector<ll> fact;\nunordered_map<string, int> vis; // visited map\nclass Solution {\npublic:\n ll count(string &s) // using basic combinatorics to count all combinations.\n {\n unordered_map<char, int> ump;\n for(auto &c : s) ump[c]++;\n vector<ll> fr(10, 0);...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "#define ll long long\nvector<ll> fact;\nunordered_map<string, int> vis; // visited map\nclass Solution {\npublic:\n ll count(string &s) // using basic combinatorics to count all combinations.\n {\n unordered_map<char, int> ump;\n for(auto &c : s) ump[c]++;\n vector<ll> fr(10, 0);...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "#define ll long long int\nclass Solution {\npublic:\n set<map<char,int>>st;\n int k1;\n void fnc(int l,int r,string s){\n if(l>r){\n if(stoll(s)%k1!=0)return ;\n map<char,int>mp;\n for(auto &t:s)mp[t]++;\n st.insert(mp);\n return ;\n ...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "typedef long long ll ;\n vector<ll>fact;\n ll ans=0;\n map<string,bool>mp;\nclass Solution {\npublic:\n\n\n bool checkdiv(string &s,int k){\n\n int rem=0;\n for(auto &x:s){\n int dig=x-'0';\n rem=(rem*10+dig)%k;\n }\n\n return rem...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "using LL = long long;\nclass Solution {\npublic:\n int n, res = 0;\n vector<int> factorial = {1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1};\n LL fac(int n) {\n if (factorial[n] != -1) return factorial[n];\n else return factorial[n] = n*fac(n-1);\n }\n void count(string& s, int k, ...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "using LL = long long;\nclass Solution {\npublic:\n int n, res = 0;\n vector<int> factorial = {1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1};\n LL fac(int n) {\n if (factorial[n] != -1) return factorial[n];\n else {\n return factorial[n] = n*fac(n-1);\n // factorial...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "using ll = long long;\nclass Solution {\npublic:\n long long countGoodIntegers(int n, int k) {\n \n vector<int> fac(11, 1);\n for(int i = 1; i < 11; i++){\n fac[i] = fac[i - 1] * i;\n }\n ll ans = 0;\n set<vector<int>> validSet;\n \n fun...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "class Solution {\npublic:\n using ll=long long;\n set<string> st;\n bool isvalid(string &s,int k){\n int n=s.length();\n for(int i=0;i<(n+1)/2;i++){\n s[n-1-i]=s[i];\n }\n ll num=stoll(s);\n // for(int i=0;i)\n return (num%k==0);\n }\n voi...
3,548
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>.</p> <p>An integer <code>x</code> is called <strong>k-palindromic</strong> if:</p> <ul> <li><code>x</code> is a <span data-keyword="palindrome-integer">palindrome</span>.</li> <li><code>x</code> is divisible by <code>k</code>....
3
{ "code": "class Solution {\npublic:\nvector<string> v; \n void solve(int n,string &s){\n if(!n){\n v.push_back(s);\n return ;\n }\n\n for(int i=0;i<=9;i++){\n string a=to_string(i);\n s.insert(s.begin()+0,a.begin(),a.end());\n s.insert(s.begin()+s.size(),a.begin(),a.end());\n solve(n-1,s); \n s...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
0
{ "code": "class Solution {\npublic:\n long long minOrders(int k, vector<int>& capacity, vector<int>& health) {\n const int n = capacity.size();\n vector<int> ind(n);\n long long s = 0;\n for (int i = 0; i < n; ++i) {\n ind[i] = i;\n s += capacity[i];\n }\n ...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
0
{ "code": "using ll = long long;\nclass Solution {\npublic:\n ll minDamage(int power, vector<int>& damage, vector<int>& health) {\n int n = damage.size();\n int indices[n];\n for(int i = 0;i < n; i++) {\n indices[i] = i;\n }\n sort(indices, indices + n, [&](int a, int ...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
0
{ "code": "int speedup = []{ios::sync_with_stdio(0); cin.tie(0); return 0;}();\nint ids[100000];\n\nclass Solution {\npublic:\n long long minDamage(int power, vector<int>& damage, vector<int>& health) {\n int N = size(damage);\n for (auto &h : health) h = (h-1)/power + 1;\n iota(ids, ids+N, 0)...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
0
{ "code": "class Solution {\npublic:\n long long minDamage(int power, vector<int>& damage, vector<int>& health) {\n int i, n = damage.size();\n long long total = 0, ans = 0;\n pair<int, int> arr[100000];\n for (i = 0; i < n; i++) {\n total += damage[i];\n health[i]...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
0
{ "code": "#include <iostream>\n#include <algorithm>\n#include <vector>\n#include <map>\n#include <queue>\n#include <set>\n#include <stack>\n#include <unordered_map>\n#include <unordered_set>\n#include <string>\n#include <string.h>\n#include <bitset>\n#include <numeric>\n#include <utility>\n#include <random>\n#includ...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
0
{ "code": "int p;\nvector<pair<int,int>> enemy;\nbool cmp(pair<int,int> a,pair<int,int> b){\n long long day1=ceil((double)a.second/p);\n long long day2=ceil((double)b.second/p);\n return a.first*day1+b.first*(day2+day1)<b.first*day2+a.first*(day1+day2);\n}\n\nclass Solution {\npublic:\n long long minDamag...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
0
{ "code": "class Solution {\npublic:\n long long minDamage(int power, vector<int>& damage, vector<int>& health) {\n int n = damage.size();\n long long total_damage = 0;\n long long current_time = 0;\n\n // Create an index array for sorting\n vector<int> indices(n);\n for (...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
0
{ "code": "class Solution {\npublic:\n long long minDamage(int power, vector<int>& damage, vector<int>& health) {\n const int n = damage.size();\n vector<int> idx(n);\n iota(idx.begin(), idx.end(), 0);\n const auto cmp = [&power, &damage, &health](const auto l, const auto r) {\n ...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
0
{ "code": "class Solution {\npublic:\n \n \n \n long long minDamage(int p, vector<int>& d, vector<int>& h) {\n int n = (int) d.size();\n for (int i = 0; i < n; i++) {\n h[i] = (h[i] + p - 1) / p;\n }\n vector<int> order(n);\n iota(order.begin(), order.end(), 0...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
0
{ "code": "#define pii pair<int,int>\n\nclass Solution {\npublic:\n long long minDamage(int power, vector<int>& D, vector<int>& H) {\n vector<int> A(D.size());\n for (int i = 0; i < D.size(); ++i) {\n H[i] = (H[i] + power - 1) / power;\n A[i] = i;\n }\n sort(A.begi...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
0
{ "code": "#include <vector>\n#include <algorithm>\n#include <numeric>\n#include <iostream>\nusing namespace std;\nclass Solution {\npublic:\n long long minDamage(int p, vector<int>& d, vector<int>& h) {\n const int n = d.size();\n long long s = 0;\n for (int i = 0; i < n; ++i) {\n ...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
0
{ "code": "class Solution {\npublic:\n static bool cmp(pair<int, int> a, pair<int, int> b) {\n return (a.first * b.second > b.first * a.second);\n }\n long long minDamage(int power, vector<int>& damage, vector<int>& health) {\n int n = damage.size(), till = 0;\n vector<pair<int, int>> ve...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
0
{ "code": "\n#include <vector>\n#include <cmath>\n#include <algorithm>\n\nclass Solution {\npublic:\n long long minDamage(int power, vector<int>& damage, vector<int>& health) {\n long long n = damage.size();\n long long total_damage = 0;\n long long current_time = 0;\n \n // Indi...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
0
{ "code": "#include <iostream>\n#include <bits/stdc++.h>\nusing namespace std;\n\n\n/****************** Aliases **********************/ \nusing ll= long long;\nusing lld= long double;\nusing ull= unsigned long long;\n\n/****************** Constants **********************/\nconst lld pi= 3.141592653589793238;\nconst l...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
0
{ "code": "class Solution {\npublic:\n long long minDamage(int power, vector<int>& damage, vector<int>& health) {\n vector<int> A(damage.size());\n for (int i = 0; i < damage.size(); ++i) {\n health[i] = (health[i] + power - 1) / power;\n A[i] = i;\n }\n ranges::so...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
0
{ "code": "class Solution {\npublic:\n long long minDamage(int power, vector<int>& damage, vector<int>& health) {\n int n=damage.size();\n long long ans=0;\n vector<pair<int,int>>pi(n);\n for(int i=0;i<n;i++){\n int a=ceil((float)health[i]/power);\n pi[i]={damage[i],a};\n }\n ...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
0
{ "code": "#define ll long long\n\nll H[100001],D[100001];\n\nbool cmp(int i,int j){\n ll x=H[i]*D[j];\n ll y=H[j]*D[i];\n if(x<y){\n return true;\n }\n else{\n return false;\n }\n}\n\nclass Solution {\npublic:\n \n long long minDamage(int power, vector<int>& d, vector<int>& h) {...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
0
{ "code": "/*\nh[i]=(h[i]+power-1)/power; is just another fancy way of writing upper bound similar to\nh[i]=ceil((double)h[i]/power) or h[i]=h[i]/power+(h[i]%power!=0)\nBob will gets damage[i] points of damage per second while they are alive (i.e. health[i] > 0).\nd=9 h=3 power=1\nenemy attack =>bob damage=9 enemy he...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
0
{ "code": "class Solution {\npublic:\n\n static bool comp(pair<int,int> a,pair<int,int> b){\n double x=(double)a.first/a.second;\n double y=(double)b.first/b.second;\n return x>y;\n }\n\n long long minDamage(int power, vector<int>& damage, vector<int>& health) {\n int n=damage.size();\n l...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
0
{ "code": "typedef long long ll;\n\nclass Solution {\npublic:\n long long minDamage(int p, vector<int>& d, vector<int>& h) {\n ll n=h.size(), sum=accumulate(d.begin(), d.end(), 0LL);\n vector<ll> idx(n);\n iota(idx.begin(), idx.end(), 0LL);\n sort(idx.begin(), idx.end(), [&](const ll& x...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
0
{ "code": "typedef long long ll;\nstruct Enemy {\n int damage;\n int p; \n};\nclass Solution {\npublic:\n long long minDamage(int power, vector<int>& damage, vector<int>& health) {\n int n = damage.size();\n vector<Enemy> enemies(n);\n for(int i = 0; i < n; ++i){\n enemies[i]....
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
0
{ "code": "/*\n 因为血量不能融合,因此每个敌人处理时长是固定的。所以总处理时间一定,那么能改变的\n 只有每个时间内收到的伤害数,我们需要尽量降低这个数值。\n 因此贪心可知,伤害高的应该有限处理,否则多生存一秒还不如让伤害低的多生存一秒。\n 同伤害情况下肯定优先处理血量低的,这样尽量减少存活数量。\n \n 但是贪心不太行,因为假设a需要x秒,b需要y秒,如果先处理a再处理b,其中a>b,那么总伤害\n ax + (x+y)*b,反之,伤害是by+(x+y)*a,作差得到bx-ay,那么如果bx-ay > 0,那么其实\n 还不如先处理b,所以排序应该考虑交叉。\n \n 80*2 + 79*3\n 79*1...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
0
{ "code": "class Solution {\npublic:\n long long minDamage(int power, vector<int>& damage, vector<int>& health) {\n int n = damage.size();\n long long ans = 0;\n\n vector<int> time(n);\n vector<pair<float,int>> r(n);\n\n for(int i = 0;i<n;i++){\n time[i] = (health[i] +...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
0
{ "code": "class Solution {\npublic:\n long long minDamage(int power, vector<int>& damage, vector<int>& health) {\n int n = damage.size();\n\n vector<int> ttk(n);\n for (int i = 0; i < n; i++)\n ttk[i] = (health[i] + power - 1) / power;\n\n vector<pair<float, int>> dif_idx(n)...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
0
{ "code": "using LL = long long;\nclass Solution {\npublic:\n long long minDamage(int power, vector<int>& damage, vector<int>& health) {\n // For two enemies,\n // if we kill enemy 0 then enemy 1, the cost is t0d0 + t1d1 + t0d1\n // if we kill enemy 1 then enemy 2, the cost is t0d0 + t1d1 + t1...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
0
{ "code": "\ntemplate <typename Tvalue>\nstruct vocab\n{\n using this_t = vocab<Tvalue>;\n\n Tvalue m_tValue;\n\n constexpr vocab(Tvalue tValue)\n : m_tValue(tValue)\n {\n }\n\n operator Tvalue () const\n {\n return m_tValue;\n }\n\n this_t & operator= (Tvalue tValue)\n {\n...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
0
{ "code": "class Solution {\npublic:\n // bool customsort(vector<int> a, vector<int> b){\n // if(a[0]!=b[0]) return a[0] > b[0];\n // else return a[1] < b[1];\n // }\n long long minDamage(int power, vector<int>& damage, vector<int>& health) {\n long long ans = 0, sum = 0;\n int n ...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
0
{ "code": "\ntemplate <typename Tvalue>\nstruct vocab\n{\n using this_t = vocab<Tvalue>;\n\n Tvalue m_tValue;\n\n constexpr vocab(Tvalue tValue)\n : m_tValue(tValue)\n {\n }\n\n operator Tvalue () const\n {\n return m_tValue;\n }\n\n this_t & operator= (Tvalue tValue)\n {\n...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
1
{ "code": "long long d[100005], t[100005], n;\n\nbool bj(const int &i, const int &j){\n return d[j] * t[i] - d[i] * t[j] < 0;\n}\n\nclass Solution {\npublic:\n long long minDamage(int power, vector<int>& dd, vector<int>& hh) {\n long long T = 0, i, res = 0;\n vector<int> a;\n n = dd.size();...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
1
{ "code": "class Solution {\npublic:\n long long minDamage(int power, vector<int>& damage, vector<int>& health) {\n int n = damage.size();\n vector<pair<double,int>> v(n);\n for(int i=0;i<n;i++){\n int time = ceil((health[i]+0.0)/power);\n v[i] = {(damage[i]+0.0)/time, i};\n }\n ...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
1
{ "code": "class Solution {\npublic:\n bool static cmp(pair<int, int>a, pair<int, int>b){\n return (long long)a.first*b.second > (long long) a.second*b.first;\n }\n long long minDamage(int power, vector<int>& damage, vector<int>& health) {\n vector<pair<int, int>>v;\n for(int i=0; i<dama...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
1
{ "code": "class Solution {\npublic:\n static bool cmp(pair<int,int> a,pair<int,int> b){\n return (1ll*a.first*b.second < 1ll*b.first*a.second);\n }\n long long minDamage(int power, vector<int>& damage, vector<int>& health) {\n long long ans = 0;\n int n = damage.size();\n vector<...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
1
{ "code": "class Solution {\npublic:\n static bool comp(const pair<int,int>&a,const pair<int,int>&b){\n int d1=a.first,d2=b.first;\n int t1=a.second,t2=b.second;\n int tot1=d1*t1+(t1+t2)*d2;\n int tot2=d2*t2+(t1+t2)*d1;\n return tot1<tot2;\n }\n long long minDamage(int powe...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
1
{ "code": "#define ll long long\n\nclass Solution {\npublic:\n static bool comp(const pair<int, int>& a, const pair<int, int>& b) {\n return (ll)a.first * b.second > (ll)b.first * a.second;\n }\n\n long long minDamage(int power, vector<int>& damage, vector<int>& health) {\n vector<pair<int, int...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
2
{ "code": "class Solution {\npublic:\n long long minDamage(int p, vector<int>& ds, vector<int>& hs) {\n vector<int> idx;\n vector<int> rs;\n for (int i=0; i<ds.size(); i++) {\n idx.push_back(i);\n rs.push_back((hs[i]+p-1)/p); // round\n }\n long long sum = a...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
2
{ "code": "class Solution {\npublic:\n long long minDamage(int power, vector<int>& damage, vector<int>& health) {\n vector<int> Time;\n int m_len = damage.size();\n vector<int> Index;\n for (int i = 0; i < m_len; i++) {\n int x = health[i];\n int y = power;\n ...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
2
{ "code": "class Solution {\npublic:\n static bool comp(pair<int,int> a, pair<int,int>b){\n return (a.first*b.second > b.first*a.second);\n }\n long long minDamage(int power, vector<int>& damage, vector<int>& health) {\n int n = damage.size();\n vector<long long> time(n);\n long l...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
2
{ "code": "class Solution {\npublic:\n #define ll long long\n #define SORT(A) std::sort(A.begin(), A.end());\n static bool cmp(const std::pair<double, std::pair<ll, ll>>& a, const std::pair<double, std::pair<ll, ll>>& b) {\n if (a.first != b.first) {\n return a.first > b.first; // Sort by t...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
2
{ "code": "class Solution {\npublic:\n static bool sortbysec(const pair<int,int> &a, const pair<int,int> &b){\n if ((double)a.first/a.second > (double)b.first/b.second){\n return true;\n }\n\n if ((double)a.first/a.second < (double)b.first/b.second){\n return false;\n ...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
2
{ "code": "class Solution {\npublic:\n long long minDamage(int power, vector<int>& damage, vector<int>& health) {\n priority_queue<pair<float,int>> pq;\n int total=0;\n vector<int> time(health.size());\n for(int i=0;i<health.size();i++){\n total+=damage[i];\n time[...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
2
{ "code": "#include <bits/stdc++.h>\nusing namespace std;\n\nclass Solution {\npublic:\n struct Enemy {\n long long p; // processing time\n long long w; // damage\n };\n \n long long minDamage(int power, vector<int>& damage, vector<int>& health) {\n int n = damage.size();\n vec...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
2
{ "code": "class Solution {\npublic:\n long long minDamage(int power, vector<int>& damage, vector<int>& health) {\n // greedy - first we will calculate a threat array which will store\n // seconds to kill a particular enemy\n // as with that we can decide which enemy to kill for minimum damage...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
2
{ "code": "class Solution {\npublic:\n long long minDamage(int power, vector<int>& damage, vector<int>& health) {\n vector<int> numMoves;\n for(int i : health) numMoves.push_back((i+power-1)/power);\n vector<pair<int, int>> info;\n long long dps = 0;\n for(int i=0;i<int(health.si...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
2
{ "code": "\nclass Solution {\npublic:\n int power;\n\n\n static bool comp(const pair<int, int>& a, const pair<int, int>& b, int power) \n {\n int one = ((a.second + power - 1) / power);\n int two = ((b.second + power - 1) / power);\n // return double(a.second) / one > double(b.second) /...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
2
{ "code": "#include <bits/stdc++.h>\n#define ll long long\n#define ld long double\nusing namespace std;\nclass Solution {\npublic:\n long long minDamage(int power, vector<int>& damage, vector<int>& health) {\n int n=damage.size();\n ll output=0;\n vector <pair<ld, int>> order(n);\n for ...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
2
{ "code": "#define ll long long\nclass Solution {\npublic:\n long long minDamage(int power, vector<int>& damage, vector<int>& health) {\n int n=damage.size();\n int sum=accumulate(damage.begin(),damage.end(),0);\n for(int i=0;i<n;i++)health[i]=ceil((health[i]*1.0)/power);\n vector<doubl...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
2
{ "code": "class Solution {\npublic:\n long long minDamage(int power, vector<int>& damage, vector<int>& health) {\n vector<pair<int,int>>v;\n int n=health.size();\n for(int i=0;i<n;i++)\n v.push_back({damage[i],health[i]});\n sort(v.begin(),v.end(),[&](pair<int,int>a,pair<in...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
2
{ "code": "class Solution {\npublic:\n long long minDamage(int power, vector<int>& damage, vector<int>& health) {\n vector<pair<int,int>>v;\n int n=health.size();\n for(int i=0;i<n;i++)\n v.push_back({damage[i],health[i]});\n sort(v.begin(),v.end(),[&](pair<int,int>a,pair<in...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
2
{ "code": "class Solution {\npublic:\n long long minDamage(int power, vector<int>& damage, vector<int>& health) {\n priority_queue<pair<float,pair<int,int>>> pq;\n int n=damage.size();\n long long ans=0;\n long long totalCost=0;\n for(int i=0;i<n;i++){\n int tm=ceil((f...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
2
{ "code": "#define ll long long\n#define pii pair<ll,ll>\n\nclass Solution {\npublic:\n long long minDamage(int p, vector<int>d, vector<int>h)\n {\n int n = d.size();\n vector< ll > s(n);\n ll sm = 0;\n vector< pii > v(n);\n for(int i=0;i<n;i++)\n {\n s[i] = ...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
2
{ "code": "class Solution {\npublic:\n bool comp(pair<float,int> n1, pair<float, int> n2) {\n if (n1.first != n2.first)\n return n1.first > n2.first;\n\n return n2.second < n1.second;\n }\n long long minDamage(int power, vector<int>& damage, vector<int>& health) {\n int n = da...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
2
{ "code": "class Solution {\npublic:\n Solution(){\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n }\n\n bool comp(pair<float,int> n1, pair<float, int> n2) {\n if (n1.first != n2.first)\n return n1.first > n2.first;\n\n return n2.second < n1.second...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
2
{ "code": "class Solution {\npublic:\n using ll = long long;\n static bool cmp (pair <ll, ll> p1, pair <ll, ll> p2) {\n return p1.first * p2.second < p2.first * p1.second;\n }\n long long minDamage(int power, vector<int>& damage, vector<int>& health) {\n for (auto &h: health) h = (h + power ...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
2
{ "code": "int p;\nclass Solution {\n \npublic:\n static bool fun(pair<int , int > a, pair<int , int > b) {\n \n int a_count = (a.second / p) + (a.second % p != 0);\n int b_count = (b.second / p) + (b.second % p != 0);\n \n int ab = a_count * (a.first + b.first) + b_count * b....
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
2
{ "code": "#define siz(a) int((a).size())\n#define ll long long\n#define pb push_back\n\nbool sortbysec(const pair<int,int> &a,const pair<int,int> &b) \n{ \n return (a.first * b.second > b.first * a.second); \n} \n \nclass Solution {\npublic:\n long long minDamage(int power, vector<int>& damage, vector<int>& h...
3,531
<p>You are given an integer <code>power</code> and two integer arrays <code>damage</code> and <code>health</code>, both having length <code>n</code>.</p> <p>Bob has <code>n</code> enemies, where enemy <code>i</code> will deal Bob <code>damage[i]</code> <strong>points</strong> of damage per second while they are <em>al...
2
{ "code": "#define ll long long\nbool compare(const pair<int,int>&a, const pair<int,int>&b) {\n return a.first * b.second > b.first * a.second;\n}\nclass Solution {\n\n\npublic:\n long long minDamage(int power, vector<int>& damage, vector<int>& health) {\n int n = damage.size();\n \n \n ...