fork download
  1. #include <bits/stdc++.h>
  2. #define VuDucNam ios_base::sync_with_stdio(false);
  3. #define Lop9a6 cin.tie(NULL);
  4. #define THCSPhamVanDong cout.tie(NULL);
  5. #define ll long long
  6. #define el cout << '\n'
  7. #define sz(a) (ll) a.size()
  8. #define all(a) a.begin(), a.end()
  9. #define fi first
  10. #define se second
  11. #define fill(a, x) memset(a, x, sizeof(a))
  12. #define file(name) \
  13.   if (fopen(name ".INP", "r")) \
  14.   { \
  15.   freopen(name ".INP", "r", stdin); \
  16.   freopen(name ".OUT", "w", stdout); \
  17.   }
  18. #define TIME (1.0 * clock() / CLOCKS_PER_SEC)
  19. #define RUNTIME cerr << "\nRuntime: " << TIME << "s.\n"
  20.  
  21. using namespace std;
  22.  
  23. const ll MOD = 1e9 + 7;
  24. const ll inf = LLONG_MAX;
  25.  
  26. int n;
  27. ll k, ans = 0;
  28. vector<ll> a;
  29. unordered_map<ll, int> mp;
  30.  
  31. void solve()
  32. {
  33. cin >> n;
  34. cin.ignore();
  35. string s;
  36. getline(cin, s);
  37. cin >> k;
  38. string tmp = "";
  39. for (int i = 0; i < sz(s); ++i){
  40. char c = s[i];
  41. if (isdigit(c) || c == '-'){
  42. if (c == '-' && tmp.empty()){
  43. if (i + 1 < sz(s) && isdigit(s[i + 1]))
  44. tmp.push_back(c);
  45. else{
  46. if (!tmp.empty()){
  47. a.push_back(stoll(tmp));
  48. tmp = "";
  49. }
  50. }
  51. }
  52. else{
  53. tmp.push_back(c);
  54. }
  55. }else{
  56. if (!tmp.empty()){
  57. a.push_back(stoll(tmp));
  58. tmp = "";
  59. }
  60. }
  61. }
  62. if (!tmp.empty()){
  63. a.push_back(stoll(tmp));
  64. }
  65. for (int i = 0; i < sz(a); ++i){
  66. ans += mp[k - a[i]];
  67. mp[a[i]]++;
  68. }
  69. cout << ans;
  70. el;
  71. }
  72.  
  73. int main()
  74. {
  75. VuDucNam Lop9a6 THCSPhamVanDong
  76. file("NHATKY");
  77. solve();
  78. RUNTIME;
  79. return 0;
  80. }
  81.  
Success #stdin #stdout #stderr 0.01s 5292KB
stdin
8
5ab2c5xy3 4a3c13d-6
7
stdout
5
stderr
Runtime: 0.004966s.